Tuesday, 7 April 2015

C Program to check whether given number is Perfect or not.

#include<stdio.h>
#include<conio.h>
main()
{
                int n,s=0,i=1;
                clrscr();
                printf("Enter a number\n");
                scanf("%d",&n);
                while(i<n)
                {
                                if(n%i==0)
                                {
                                                s=s+i;
                                }
                                i++;
                }
                if(s==n)
                {
                                printf("\n%d is a perfect number.",n);
                }
                else
                {
                                printf("\n%d is not a perfect number",n);
                }
}

No comments:

Post a Comment