| Previous | Home | Next |
*A Perfect number is number which is sum of factor is equals to itself
To check a number is perfect or not. We have first find its factor and add these factors and store into a variable. At last check is it equals to number itself ? If it is equals itself then it is perfect number otherwise it is not perfect number.
/* check a number is perfect or not,
( perfect number is sum of its factor number) */
#include<stdio.h>
#include<conio.h>
void main()
{
int i, p,sum=0;
clrscr();
printf("Enter a number :\t");
scanf("%d", &p);
for(i=1;i<=p;i++)
{
if(p%i==0)
sum=sum+i;
}
if(sum==p)
printf("Number is perfect");
else
printf("Number is not perfect");
getch();
}
Enter a number : 169
Number is not perfect
| Previous | Home | Next |