Search



Thursday, 26 February 2015

Perfect number

In this program, for loop and if else functions are used. "for(i=1;i<n;i++)" and if((n%i)==0) these conditions are performing the major task in this program.

Program to check Perfect Number.

#include<stdio.h>
#include<conio.h>
void main()
{ int n,sum=0,i;
clrscr();
printf("\n to check whether no.is perfect or not");
printf("\n\n enter no : ");
scanf("%d",&n);
for(i=1;i<n;i++)
{    if((n%i)==0)
    { sum = sum + i;
    }
    i++;
}
if(n==sum)
printf("\n\n %d is a perfect no.",i);
else
printf("\n\n %d is not a perfect no.",i);
getch();
}


No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.