Wednesday, May 09, 2012

C Program To Check Whether The Given Number Is Perfect/Abundent/Deficient


Hello guys  today i'm discussing a program that check whether the inputed number is perfect,deficient or abundent.A number is said to be perfect if the sum of all the divisors of that number (except number) is equal to number.For example 6 is a perfect number because divisors of 6 are 1,2,3 and 1+2+3=6,similiarly 28(1+2+4+7+14) is perfect number.It is a very simple code just read it carefully.

#include<stdio.h>
#include<conio.h>
void main()
{
 long int num,i,sum=0;
 clrscr();
 printf("\n Enter the number:");
 scanf("%ld",&num);
 for(i=1;i<num;i++)
 {
  if(num%i==0)
   sum=sum+i;
 }
 if(sum==num)
 {
  printf("\n number %ld is perfect:",num);
 }
 else if(sum>num)
 {
  printf("\n number %ld is abundent:",num);
 }
 else if(sum<num)
 {
  printf("\n number %ld is deficient:",num);
 }
 getch();
}





Thanks Guys....

No comments:

Post a Comment

Please Give Me Your Views

Popular Posts