**Q.**Write a C program to check whether a given number is a perfect number or not.

**Ans.**

*Definition of*A positive integer

**Perfect number**:*n*is called a

**perfect numbe**r if it is equal to the sum of all of its positive divisors, excluding n itself.

**For example**,

*6*is perfect integer number, because 1, 2 and 3 are its proper positive divisors and 1+2+3=6.

The next perfect number is

*28*because 1+2+4+7+14=28.
The next perfect number is

*496*because
1+2+4+8+16+31+62+124+248=496.

/*program to check whether a number is perfect or not*/

**#include**<stdio.h>

**#include**<conio.h>

**int**main()

**{**

int i,n,num,sum=0;

printf("Enter a number : ");

scanf("%d",

**&**num);
n=num;

for(i=1; i<n; i++)

{

if(num%i==0)

sum=sum+i;

}

if(num==sum)

printf("Given number is Perfect Number ");

else

printf("Given number is Not Perfect Number ");

getch();

getch();

**return****0**;**}**

__Output__:-
Enter a number :

**7543****Given number is Not Perfect Number**

Enter a number :

**8128****Given number is Perfect Number**

*Related Programs:*

sir write c program for perfect number using function.

ReplyDelete@Dharmendra Singh,

Deleteyour required program perfect number in C using function at:

http://cprogrammingcodes.blogspot.com/2015/09/perfect-number-in-c-using-function.html

Sir write a program for perfect number using arry

ReplyDelete