How to Check Whether Number is Perfect Or Not using C

C Program to Check Whether Number is Perfect Or Not


#include <stdio.h>

int main() {
   int num, i = 1, sum = 0;

   printf("Enter a number: ");
   scanf("%d", &num);

   while (i < num) {
      if (num % i == 0) {
         sum = sum + i;
      }
      i++;
   }

   if (sum == num)
      printf("%d is a Perfect Number", i);
   else
      printf("%d is Non Perfect Number", i);

   return 0;
}
How to Check Whether Number is Perfect Or Not using C

Published on 12-Dec-2021 9:31:51

You may also like this!