Skip to main content

Program to identify and print perfect number in C Language

This C Program is for to identify perfect number. Here program is accepting range up to which need to identify perfect number. Perfect number is  a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. for example 6 where it is divisible for 1, 2, 3 so sum of it is 6. To write this program we have used two for loop along with simple if condition.

// Program to find perfect number
#include <stdio.h>

int main() {
    // Write C code here
    int rangeNo,counterNo,perSum;
    printf("\n\tEnter Range to find perfect number \t");
   //Loop to find divisible numbers 

    for (int i = 1;i<=rangeNo;i++)
          for (int j = 1;j<i;j++)
                if (i%j == 0)
                perSum = perSum + j;
            if (perSum == i)
            printf("\n\t %d is perfect number ",i);
    return 0;


Enter Range to find perfect number 	10000
6 is perfect number 
28 is perfect number 
496 is perfect number 
8128 is perfect number