Solved

Question

Posted on 2004-10-28
216 Views
Last Modified: 2010-04-15
How do I write a script that determines if a number is a Perfect Number or if it is a Prime Number?
0
Question by:testn1
    8 Comments
     
    LVL 2

    Accepted Solution

    by:
    find all the proper divisors of the number. if there is only one (1), then the number is prime. otherwise, add the divisors. if the summation equals the number itself, it's a perfect number.

    you can look up on the Sieve of Eratosthenes for effective way of finding a lot of prime numbers.

    -- Adil
    0
     
    LVL 45

    Expert Comment

    by:sunnycoder
    testn1,

    This sounds like a homework assignment .. Let us see the work that you have done so far.

    sunnycoder
    0
     
    LVL 6

    Expert Comment

    by:stsanz
    How do I title a question asking how to write a script that determines if a number is a Perfect Number or if it is a Prime Number?
    0
     
    LVL 12

    Expert Comment

    by:stefan73
    Hi stsanz,
    Title it "Moo"? :-)
    0
     
    LVL 2

    Expert Comment

    by:shah1d1698
    Here is some code to do your job...
    Use the following two functions in your program and see whether it works or not.

    <code edited by sunnycoder, Page Editor>
    0
     
    LVL 2

    Expert Comment

    by:shah1d1698
    Did my functions work???
    0
     
    LVL 2

    Expert Comment

    by:shah1d1698
    Sorry..I messed up..
    0
     
    LVL 2

    Assisted Solution

    by:shah1d1698
    >>To testn1....

    u'll find useful info about determining perfect number at the following site..

    http://home1.pacific.net.sg/~novelway/MEW2/lesson1.html
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now