Perfect Number in C

By | October 4, 2021
Perfect Number in C

Here in this program, we will write a code which checks whether the entered number is a Perfect number or not.

What is a Perfect number?

When a positive integer is equal to the sum of its all possible divisors except itself, is known as a perfect number.

For example, 6 is a perfect number because the sum of its all divisors is equal to 6

Divisors of 6 are 1, 2, 3 exclude 6.

Sum of 6 all divisors = 1+2+3 = 6

Statements to use:

  • For loop
  • If statements
  • Else statement


  • First, we will ask the user to enter a positive integer
  • Then we start a loop from 1 to the half of the entered number
  • Inside the loop, we will check which number is the divisor of the entered number.
  • If the number is a divisor of the entered number, we will sum it.
  • At last, we will check whether the summing of all the divisors is equal to the entered number or not
  • If it is equal to the entered number, we will print It is a perfect number, is not we will print it is not a perfect number.

Perfect Number in C

void main()
int num, sum=0,i;
printf("Enter a Positive Integer: ");
if (num==1)
    printf("It is not a Perfect number");
        printf("It is a perfect number");
        printf("It is not a perfect number");



Enter a Positive Integer: 6

It is a perfect number


People Aare also reading:

Author: Vinay Singh

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published.