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
#include<stdio.h>
int
main(){
int n,i=1,sum=0;
printf("Enter a number: ");
scanf("%d",&n);
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",n);
else
printf("%d is not a perfect number",n);
return 0;
}
Sample
output:
Enter
a number: 6
6
is a perfect number
No comments:
Post a Comment