2 Aug 2019

  • August 02, 2019
  • Amitraj









Perfect Number in C

Here you will get program for perfect number in C.

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

For example:

28 is a perfect number as 1 + 2 + 4 + 7 + 14 = 28.

15 is not perfect number as 1 + 3 + 5 is not equal to 15.


Below I have shared a program to check whether a number is a perfect number or not.


/*   C Program to verify a given no. is perfect or not */

#include<stdio.h>

int main()
{

int n,sum=0,i=1;

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

while(n>i)
{
if(n%i==0)
sum=sum+i;
i++;

}
if(sum==n)
printf("Perfect Number");
else

printf("Not Perfect Number");
return 0;
}


INPUT/OUTPUT:
Enter a no:28
Perfect Number

http://codevidyalay.blogspot.com




Translate

Popular Posts