9.12.2015

Perfect Number In C Using Function

Q. Write a C program to identify the user entered number is perfect number or not.

Ans.

/* perfect number in c using function program */
#include<stdio.h>
int perfect(int  );
int main()
{

  int num;
  printf("Enter any number : ");
  scanf("%d", &num);
  perfect(num);
  getch();
  return 0;
}
int perfect(int num)
{
  int n,sum=0,i;
  n=num;
  for(i=1; i<n; i++)
  {
     if(num%i==0)
        sum=sum+i;
  }
  if(num==sum)
     printf("%d is Perfect Number",num);
  else
     printf("%d is not Perfect Number",num);
}

/********************************************
The output of above program would be:
*********************************************/

Output of Perfect number in C using function program
Figure: Screen shot f or Perfect number in C using function program

You might also like:

  1. What is perfect number?
  2. Perfect number in C program
  3. Amicable number in C program
  4. Armstrong number range in C program
  5. Search Armstrong number C program
  6. Flowchart for check a number is Armstrong or not


No comments:

Post a Comment