Like us on google+

Thursday, 7 November 2013

Widgets

C PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PERFECT NUMBER OR NOT.

#include<stdio.h>
int main()
{
  int n,i=1,sum=0;

  printf("Enter a number: ");
  scanf("%d",&n);

  while(i<n)
  {
      if(n%i==0)
      sum=sum+i;
      i++;
  }
  if(sum==n)
      printf("%d is a perfect number",i);
  else
      printf("%d is not a perfect number",i);

  return 0;
}
-----------------------------------------------------
Sample output 1:
Enter a number: 6
6 is a perfect number


Sample output 2:
Enter a number: 7
7 is a not a perfect number

-----------------------------------------------------
Perfect number is a positive number which is equal to its sum of positive divisors excluding itself.

For example:Consider 6.Its positive divisors excluding itself are 1,2 and 3.Sum of 1+2+3=6 therefore 6 is a perfect number and 6 is the smallest perfect number.

Consider 7: Its positive divisors excluding itself is 1 which is not equal to 7.Hence its not a perfect number.

------------------------------------------------------

SHARE THIS POST   

  • Facebook
  • Twitter
  • Myspace
  • Google Buzz
  • Reddit
  • Stumnleupon
  • Delicious
  • Digg
  • Technorati
About us:
Hi guys Sandesh and Rajesh here ... studing engineering in PESIT started this blog as a google contest and also we love blogging ...Hope u like it ...Encourage us by liking us on g+... Any queries dont hesitate to ask Read More →

0 comments: