PERFECT NUMBER OR NOT
Consider the following I/O samples.
SAMPLE INPUT: 6
SAMPLE OUTPUT: PERFECT NUMBER
A number is called a PERFECT NUMBER if it is equal to the sum of it's positive divisors, excluding the number itself.
6 = Divisors of 6 are - 1,2,3
1+2+3=6
6==6
C PROGRAM:#include<stdio.h>int main()
{
int n,i,sum=0;
scanf("%d",&n);
for(i=1;i<n;i++)
{
if(n%i==0)
sum+=i;
}
if(sum==n)
printf("Perfect Number");
else
printf("Not a Perfect Number");
return 0;
}
OUTPUT:The given source code in C program "FOR PERFECT NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment