# Perfect Number C Program

## C Program To Find Perfect Number

Learn How To Find Perfect Number in C Programming Language. It is important that we should know **How A For Loop Works** before getting further with the C Program Code. You will have to make use of **Modulus Operator** to Find Numbers that are Perfect in C Code.

#### What is a Perfect Number?

It is a Positive Integer (or Number) which is equal to the Sum of their proper Positive Divisors, excluding the **Number** itself.

#### Example

**6, 496, 28, 8128**

**Must Read: C Program To Check if a Number is a Perfect Square Number or Not**

#### C Program For Perfect Number using While Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<stdio.h> int main() { int num, sum = 0, count = 1; printf("Enter A Number:\t"); scanf("%d", &num); while(count < num) { if(num%count == 0) { sum = sum + count; } count++; } if(sum == num) printf("%d is a Perfect Number", num); else printf("%d is not a Perfect Integer", num); printf("\n"); return 0; } |

**Must Read: C Program To Find Quadratic Roots of an Equation**

#### C Program To Find Perfect Number using For Loop

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> int main() { int num, sum = 0, count; printf("Enter A Number:\t"); scanf("%d", &num); for(count = 1; count < num; count++) { if(num%count == 0) { sum = sum + count; } } if(sum == num) printf("%d is a Perfect Number", num); else printf("%d is not a Perfect Integer", num); printf("\n"); return 0; } |

**Must Read: C Program To Calculate Greatest Common Divisor (GCD) of Two Numbers**

#### Check Perfect Number using Function in C Programming

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include<stdio.h> int check_perfect_number(int x) { int sum = 0, count = 1; while(count < x) { if(x%count == 0) { sum = sum + count; } count++; } return sum; } int main() { int num, result; printf("Enter A Number:\t"); scanf("%d", &num); result = check_perfect_number(num); if(result == num) printf("%d is a Perfect Number", num); else printf("%d is not a Perfect Integer", num); printf("\n"); return 0; } |

**Must Read: C Program To Find Sum of Digits of an Integer**

#### Output

If you have any compilation errors or doubts in this C Program To Find Perfect Numbers, let us know about in the Comment Section below.

Thanks. I was looking for perfect number program in c using function. You have given so many ways to solve the perfect numbers.

We are glad that you liked the Perfect Number C Program. We have given 3 methods as we feel that it would help programming beginners to understand it in a much better way with comparison of different methods.