PDA

View Full Version : Coding a c++ program


ziba
Oct 27, 2007, 05:40 PM
I need a fast help to code the following program which is really easy:

I have to develop a program to analyze one or more numbers entered by a user and see if the number is a prime # or a perfect # and out put a list of divisors of all perfect numbers and noneprime numbers.

Hint: A prime # is a # whose only exact divisors are 1 and the number itself(such 2,3,5,7) and a perfect # is a # whose exact divisors (except the number itself) sum to equal the number.(For example #6 has 3 divisors(not including 6). The divisors of 6(1,2,3)sum to equal the number.

I will appreciate your help if u give me the answer within 24 hours.

asterisk_man
Oct 27, 2007, 06:05 PM
We're not here to do your homework. Next time try asking questions before the assignment is due tomorrow. We can help you with questions and review your answer but we won't do the work for you.

red_cartoon
Nov 22, 2007, 11:04 AM
If you are new to programming, then this is certainly not a good idea to start working on these problem just the day before submission. I hope you are in a much better situation than that.

For checking whether a number is prime or not, you run a loop I = 1 to I = sqrt(n) and see if I divides n without any reminder. If none of these can divide n without a reminder then n is prime.

For perfect number checking, loop from 1 to n and collect the divisors as you go through the loop. Add them to see whether they sum up to n or not. That's it.