GoogelAddUnit1

Monday, 16 April 2012

WRITE A C-PROGRAM TO TEST THE GIVEN NUMBER IS PERFECT NUMBER (OR) NOT.

AIM:A program to test the given number is perfect number (or) not.
PROGRAM:
#include<stdio.h>
main()
{
int i,n,sum=0;
printf("enter the value of n");
scanf("%d",&n);
for(i=1;i<n-1;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
printf("it is a perfect number");
else
printf("it is not a perfect number");
}

OUTPUT:
enter the value of n
6
it is a perfect number
enter the value of n
1
it is not a perfect number

No comments:

Post a Comment