c program to find all perfect numbers

c program to find all perfect numbers

Page 1 of 1

6 Replies - 8091 Views - Last Post: 14 August 2008 - 12:06 PM Rate Topic: -----

#1 arnabraha1989  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head

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

Re: c program to find all perfect numbers

Post icon  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.
Was This Post Helpful? 0
  • +
  • -

#3 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: c program to find all perfect numbers

Posted 14 August 2008 - 09:22 AM

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#4 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: c program to find all perfect numbers

Posted 14 August 2008 - 09:24 AM

please don't double post.

[rules][/rules]

:)
Was This Post Helpful? 0
  • +
  • -

#5 Akelo  Icon User is offline

  • D.I.C Head

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

Re: c program to find all perfect numbers

Posted 14 August 2008 - 10:02 AM

View Postarnabraha1989, 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.

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.
Was This Post Helpful? 0
  • +
  • -

#6 Sepanto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#7 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1