Summary: In this programming example, we will learn to check the perfect number in C and also learn to print all perfect numbers in the given range.

If the sum of all factors of a number ( exclusive itself ) is equal to the original number, then it’s a Perfect number. E.g. 6, 28, etc.

Perfect Number in C

Steps to Check Perfect Number in C:

  1. Input a number.
  2. For loop from i=0 to i<num/2:
    1. Check whether i is divisible by num. If yes, then add it to the sum.
  3. After the loop is over, Check whether sum == num:
    1. If yes, then the number is perfect, else not.

Here is the implementation of the steps in C:


Enter a number
Perfect Number

Print all Perfect Number in the Given Range


Enter a lower and upper range value: 1 1000
6 28 496

In the above program, we have created a separate function that uses the same logic as the above program to check whether the passed number is a Perfect number or not.

We iterate through all the numbers in the given range and individually check them by passing the number to the isPerfect() method.

In this tutorial, we learned to check whether a given number is a perfect number or not in the C programming language.

This Post Has 2 Comments

  1. Sneha Singh

    I want a program of fascinate number in c and java

Leave a Reply

14 + twenty =