C Program to check a number is perfect number or not


In this program, You will learn how to check a number is perfect number or not in C.


Some list of perfect numbers is : 6, 28, 496, 8128


Example: How to check a number is perfect number or not in C

Run it Now
#include<stdio.h>

int main() {

   int n, i, s = 0;

   printf("Enter a Number :");
   scanf("%d", &n);

   for (i = 1; i < n; i++) {
       if (n % i == 0) {
           s = s + i;
       }
   }

   if (n == s) {
       printf("\nIt is a Perfect Number :%d", n);
   } else {
       printf("\nIt is Not a Perfect Number :%d", n);
   }

   return 0;
}

Output:

Enter a Number :28
It is a Perfect Number :28