C Program to check given number perfect or not
What is Perfect Number
A Positive integer will be called perfect number if the sum of its all divisor is equal to that number, excluding the number itself.
For Ex:- 6
The divisors of 6=1,2,3;
1+2+3=6;
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,r,i;
clrscr();
printf("Enter any number\n");
scanf("%d",&n);
for(i=1;i<n;i++)
{
r=n%i;
if(r==0)
sum=sum+i;
}
if(sum==n)
printf("Entered number is a perfect Number");
else
printf("Entered number is not a perfect Number");
getch();
}
OUTPUT
Enter any number
496
Entered number is a perfect Number
You can also visit:-