Perfect Number : A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. For example 6 is a perfect number because 1 + 2 + 3 = 6 that is equal to number itself.
#include<stdio.h>
int main()
{
int no, i = 1, sum = 0;
printf("Enter No : ");
scanf("%d", &no);
while( i < no )
{
if( no % i == 0 )
sum = sum + i;
i++;
}
if( sum == no )
printf("\nPerfect Number");
else
printf("\nNot Perfect Number");
return 0;
}
0 comments :
Post a Comment