C program to check whether a given number is perfect number
In this program, I have discussed about the C program to check whether a given number is perfect number
A number is called a perfect number if the sum of all the divisors of that number is equal to that number.
For example:- 6,,,,,,,, 1+2+3=6.
int main()
{ int n,sum=0,k,i;
printf("Enter the number:");
scanf("%d",&n);
k=n/2;
for(i=1;i<=k;i++)
{ if(n%i==0)
{ sum=sum+i;
}
}
if(n==sum)
{printf("Perfect Number !!");
}
else
printf("Not a perfect number !!");
}
Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.
Enjoy programming in C.
0 comments:
Post a Comment