## Description

## Write a c program to check that given number is a Perfect Number or Not.

Before Write the program First of all we know about that what is perfect number.

**What is Perfect Number?**

A Number is called **Perfect number **, positive integer number that is equal to the sum of the its possible factor.

For Example :

**6 is a Perfect Number Or Not.** Let's Check

The Possible factors of 6 is 1, 2, 3. So these are the possible factors of 6 So now add(sum) these factors 1 + 2 + 3 = 6.

6 is a Perfect Number.

Now Let's Start the Code....

```
#include<stdio.h>
int main(){
int n;
printf("Enter the Number : ");
scanf("%d", &n);
int sum = 0;
for(int i=1; i<n; i++){
if(n%i==0){
sum = sum + i;
}
}
if(sum == n){
printf("%d is the Perfect Number",n);
}else{
printf("%d is Not Perfect Number",n);
}
return 0;
}
```

**Output :**

Enter the Number : 28

28 is the Perfect Number

**How its work?**

Step 1 : Initilized a variable n. which stores the value of given by user.

Step 2 : Initilized a another variable sum. which stores the sum of factors of given number. Here we initial assgined the value is zero ( 0 ).

Step 3 : Start the for loop, in for loop we initilized a variable i which is initial assigned the value is one ( 1 ), this loop is work until the given condition is will be false. Condition is ( i < n ). when this condition is true then repeat the step 4.

Step 4 : If ( n % i == 0 ) is true the go to and execute this pieace of code ( sum = sum + i ).

Step 5 : After complete this process we compare the given value n is and sum if the both are equal then we print given number is Perfect Number otherwise print given number is Not Perfect Number.

Thanks..

Comment Please...

## Recommended Posts

## Strong Number in C programming | What is Strong Number

Strong Number is a number whose sum of the factorial of digits of number is equal to given number.

For Example : 145 is a strong number.

## Neon Number | c programming language

A neon number is a number if the sum of the square of that number is equal to the actual number, then it is a neon number. For Example : 9 is a neon number.

## C programming restaurant menu code | @lapmos

In this tutorial we write a c program which print the menus of restaurant with product and price.

## Primary Arithmetic program in c programming and cpp programming language

Write a c and c++ programming language , primary Arithmetic Program

## Automorphic Number | C programming language | @lapmos

An automorphic number is a number that has the same digit at the end of the square as the given number is an automorphic number. For Example : 25 is a Automorphic Number.

## 9 basic program in cpp programming language | @lapmos

In this post we write the 9 basic program in c programming language which is based the basic understanding of c++ programming language.