# c program to find all perfect numbers

Page 1 of 1

## 6 Replies - 8979 Views - Last Post: 14 August 2008 - 12:06 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=60628&amp;s=8d3dc5577db9f08d44f9484fbfc7d5d0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 arnabraha1989

Reputation: 3
• Posts: 14
• Joined: 02-August 08

# c program to find all perfect numbers

Posted 14 August 2008 - 08:25 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.
Is This A Good Question/Topic? 0

## Replies To: c program to find all perfect numbers

### #2 arnabraha1989

Reputation: 3
• Posts: 14
• Joined: 02-August 08

## 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.

### #3 red_4900

• Code T(h)inkers

Reputation: 21
• Posts: 1,120
• Joined: 22-February 08

## Re: c program to find all perfect numbers

Posted 14 August 2008 - 09:22 AM

[rules][/rules]

### #4 red_4900

• Code T(h)inkers

Reputation: 21
• Posts: 1,120
• Joined: 22-February 08

## Re: c program to find all perfect numbers

Posted 14 August 2008 - 09:24 AM

[rules][/rules]

### #5 Akelo

Reputation: 4
• Posts: 98
• Joined: 12-December 07

## 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.

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.

```/* 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()
{
/*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 Sepanto

Reputation: 0
• Posts: 97
• Joined: 20-March 08

## 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 NickDMax

Reputation: 2255
• Posts: 9,245
• Joined: 18-February 07

## 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 On-Line 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.