recent

C Program To Check Whether Number Is Perfect Or Not

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: \n");
   scanf("%d", &num);  //input from user

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

   if (sum == num)
      printf("%d is a Perfect Number\n", i);   //Print Output On screen
   
   else
      printf("%d is Non Perfect Number\n", i);   //Print Output On screen

}
Powered by Blogger.