Translate

Labels

Showing posts with label PERFECT NUMBER. Show all posts
Showing posts with label PERFECT NUMBER. Show all posts

Wednesday, 12 June 2013

PROGRAM TO GENERATE PREFECT NUMBERS

main()
{
int n,i,sum=0,count=0;
for(n=4; ;n++)
{
sum=0;
for(i=1;i<n/2;i++)
{
if((n%i)==0)
sum+=i;
}

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();
}