Write a C program to check whether a input number is perfect number of not.
#include<conio.h>
#include<stdio.h>
void main()
{
int no,i,sum;//no=number, sum=sum of divisor
//accept number
printf("\nEnter any number: ");
scanf("%d",&no);
sum=0;
//check divisors of n
for(i=1;i<no/2;i++)
{
if(i%2==0)
{
sum=sum+no;
}
}
//to check original number and sum of divisor till given number
if(sum==no)
{
printf("\n%d is Perfect Number.",sum);
}
else
{
printf("\n%d is not Perfect Number.",no);
}
getch();
}
0 Comments