Translate

Labels

Saturday 29 December 2012

FINDING A PERFECT NUMBER

A Perfect number is a number that is the sum of all divisors except itself  six is a perfect number 

since the sum of divisors of except itself is 1+2+3=6

#include<stdio.h>
#include<conio.h>
void main()
{
int num,div,i,u,sum=0,r;
clrscr();
printf("Enter any number:");
scanf("%d",num);
i=1;
while(i<num)
{
div=num%i;
r=num%i;
if(r==0)
{
sum=sum+i;
printf("\n\n The divisible number:%d",i);
}
i=i+1;
}
printf("\n\n The sum is%d \n ",sum);
if(sum= =num)
printf("\n Hence%d is a perfect number",num);
else
printf("\n Hence %d is not a perfect number",num);
getch();
}

No comments: