Check perfect number in C by R4R Team

Perfect number :
-The sum of all factors of number are equal to that number then number is known as perfect number.

Example-
6 is a perfect number.
Factors 1,2,3 and there sum is also 6

program-

#include< stdio.h>
int main() {
int i,n=0,sum=0;
printf("Enter Number\n");
scanf("%d",&n);
for(i=1;i< n-1;i++)
{
if(n%i==0)
sum=sum+i;
}
if(n==sum)
printf("Perfect number");
else
printf("Not Perfect number");

}


output-

Enter Number
6
Perfect number

Enter Number
28
Perfect number

Enter Number
5
Not Perfect number

-In this program, we take an input of the integer number and try to check it is perfect number or not.
-Firstly we find all factors of that number and add all factor.
-At last compare both number, if they are same then it is perfect number otherwise it's not.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!