can any expert help me in writing a C program to find all the perfect numbers.
a perfect number is a number in which on addition of all the factors we get the number itself.
for example,
6. the factors of 6 are 1,2,3 and on addition
1+2+3=6.
6 Replies  8091 Views  Last Post: 14 August 2008  12:06 PM
Replies To: c program to find all perfect numbers
#2
Re: c program to find all perfect numbers
Posted 14 August 2008  08:30 AM
can any expert help me in writing a C program to find all the perfect numbers.
a perfect number is a number in which on addition of all the factors we get the number itself.
for example,
6. the factors of 6 are 1,2,3 and on addition
1+2+3=6.
a perfect number is a number in which on addition of all the factors we get the number itself.
for example,
6. the factors of 6 are 1,2,3 and on addition
1+2+3=6.
#3
Re: c program to find all perfect numbers
Posted 14 August 2008  09:22 AM
[rules][/rules]
#4
Re: c program to find all perfect numbers
Posted 14 August 2008  09:24 AM
please don't double post.
[rules][/rules]
[rules][/rules]
#5
Re: c program to find all perfect numbers
Posted 14 August 2008  10:02 AM
arnabraha1989, on 14 Aug, 2008  08:30 AM, said:
can any expert help me in writing a C program to find all the perfect numbers.
a perfect number is a number in which on addition of all the factors we get the number itself.
for example,
6. the factors of 6 are 1,2,3 and on addition
1+2+3=6.
a perfect number is a number in which on addition of all the factors we get the number itself.
for example,
6. the factors of 6 are 1,2,3 and on addition
1+2+3=6.
More than happy to help, however, you need to show that you've done your homework so to speak. You need to provide code, and then you'll get more of a response.
You don't need an expert to do what you need, just need to follow some basic tutorials for basic input/output in cc.
your basic structure will be:
/* more includes depending if you need to use advanced math or other libraries*/ #include <stdio.h> /* function prototypes here if you want to make a function to find the perfect number.*/ /* main meat of the program */ int main() { /*declare your variables*/ /*put in the code here to calculate the perfect number */ /*output the information that you calculated*/ return 0; } /* function definitions for the function prototype...if you didn't make a function prototype, or don't even want to make a function, then disregard this part */
Come up with the equation that will allow you to find the perfect number. I just gave you the very skeleton of ANY basic program. If you have questions about how it works, you need to start reading some tutorials. If you need to know which libraries, then ask specific questions. We won't do your homework for you.
#6
Re: c program to find all perfect numbers
Posted 14 August 2008  10:05 AM
How about looping through all the unsigned integers (or even long unsigned integers) and checking whatever they are perfect, and than recording those that are perfect in a txt file?
#7
Re: c program to find all perfect numbers
Posted 14 August 2008  12:06 PM
well it is supposed that there are in infinite number of perfect numbers, but even in the first few they are sparsely distributed.
6
28
496
8128
33550336
8589869056
137438691328
2305843008139952128
So you are not going to get very far with a linear search or using the int or long data types.
Unfortunately the rules say we can't just give you code, you have to show some effort.
[rules][/rules]
a good resource on this would be the The OnLine Encyclopedia of Integer Sequences!
Apparently you want to look for Mersenne Primes... There is a distributed effort going on to find new Mersenne Primes. We don't really know how to calculate them we just have to search for them.
6
28
496
8128
33550336
8589869056
137438691328
2305843008139952128
So you are not going to get very far with a linear search or using the int or long data types.
Unfortunately the rules say we can't just give you code, you have to show some effort.
[rules][/rules]
a good resource on this would be the The OnLine Encyclopedia of Integer Sequences!
Apparently you want to look for Mersenne Primes... There is a distributed effort going on to find new Mersenne Primes. We don't really know how to calculate them we just have to search for them.
Page 1 of 1
