A perfect number is a number which is equal to the sum of its divisor. For eg, divisors of 6 are 1,2, and 3. The sum of these divisors is 6. So 6 is called a perfect number.
PROGRAM:
PROGRAM:
#include<stdio.h>
int main()
{
int sum=0,i,n;
scanf("%d",&n);
for(i=1;i<=n-1;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
printf("It is a perfect number");
else
printf("Not a perfect number");
return 0;
}
OUTPUT:
6
It is a perfect number
No comments:
Post a Comment