Saturday, 1 October 2011

Perfect Number

#include<stdio.h>
#include<conio.h>
int main()
{
int num,i=1,sum=0;
printf("Enter a number=");
scanf("%d",&num);
while(i<num)
{
if(num%i==0)
sum=sum+i;
i++;
}
if(sum==num)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);
getch();
return 0;
}

No comments:

Post a Comment