Program to Check Whether Number is Perfect Or Not

Program to Check Whether Given Number is Perfect Or Not ?
#include<stdio.h>
int main()
{
int n,i=1,sum=0;
  printf("nEnter a number: ");
  scanf("%d",&n);
  while(i<n){
      if(n%i==0)
           sum=sum+i;
          i++;
  }
  if(sum==n)
      printf("n%d is a Perfect Number",i);
  else
      printf("n%d is Non Perfect Number",i);
  return 0;
}

Share this

Related Posts

Previous
Next Post »