Testing.

Saturday, 21 January 2017

C programming language: C program to check given number is perfect number or not.

Perfect number is a positive integer number  that is equal to the sum of its divisors.
Example: 6 is the smallest perfect number in number system.
                Here divisors of 6 is 1,2 and 3.
                Here 1+2+3=6 is a perfect number.
-------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum=0;
printf("\nEnter Number To Check :");
scanf("%d",&num);
     for(i=1;i<=num/2;i++)
     {
       if(num%i==0)
  sum=sum+i;
     }
   if(num==sum)
     printf("\n %d Is a Perfect Number...",num);
else
printf("\n %d Is Not a Perfect Number...",num);
getch();
}



No comments:

Post a Comment