Follow by Email

Friday, June 10, 2011

Find out the perfect number using c program

#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("\nThe no %d is a perfect number",i);
  else
      printf("\nThe no %d is not a perfect number",i);
  return 0;
}

No comments:

Post a Comment