Home » NO IDEA » Perfect Number

Perfect Number

Blog Stats

  • 15,880 hits
December 2012
M T W T F S S
« Sep   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

 PERFECT NUMBER

 Definition of perfect number or What is perfect number?

Perfect number is a positive number which sum of all positive divisors
* excluding that number is equal to that number.
* For example 6 is perfect number since divisor of 6 are 1, 2 and 3.
* Sum of its divisor is
1 + 2+ 3 =6

Note: 6 is the smallest perfect number.

Next perfect number is 28 since 1+ 2 + 4 + 7 + 14 = 28
Some more perfect numbers: 496, 8128

//check whether the give number is perfect or not
#include<stdio.h>
int main()
{
int num,sum;
sum=0;
printf("\n Enter the number");
scanf("%d",&num);
int i;
for(i=1;i<num;i++)
{
if((num%i)==0)
sum=sum+i;
}
if(num==sum)
printf("\n the given number is perfect number");
else
printf("\n the given number is not perfect number");
return 0;
}

//generation of the perfect number for the given range

#include<stdio.h>
 int main()
 {
 int num,i,sum;
 int range;
 printf("\n Enter the range");
 scanf("%d",&range);
 for(num=1;num<=range;num++)
 {
 sum=0;
 for(i=1;i<num;i++)
 {
 if((num%i)==0)
 sum=sum+i;
 }
 if(sum==num)
 {
 printf("\n%d",sum);
 }

}
 return 0;
 }

Advertisements

1 Comment

  1. […] write a c program to check whether  the given number is  perfect number  […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: