PROGRAM TO CHECK IF A GIVEN NUMBER IS PERFECT NUMBER OR NOT

/*PROGRAM TO CHECK IF A GIVEN NUMBER IS PERFECT NUMBER OR NOT*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,temp=0,a;
clrscr();
printf(“Enter the number: “);
scanf(“%d”,&n);
a=n;
for(i=1;i<=a;i++)
{
if(a%i==0)
{
temp=temp+i;
a=a/i;
}
}
if(temp==n)
printf(“Number %d is a perfect number”,n);
else
printf(“Number %d is not a perfect number”,n);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *