C program to Check whether a Number is Perfect or Not

C program to Check if a Number is Perfect

A number is Perfect, if sum of all it’s divisors is equal to the original number.

      consider a number 6, it has 3 divisors, where 1, 2 and 3. Where 1+2+3=6
Hence 6 is a Perfect number.

% is the remainder after division (modulo division) arithmetic operator in C.
11 % 5 = 1 (11 / 5 = 2 with remainder 1)

/*C Program to find whether the number is 
Perfect number or not*/
#include <stdio.h>
void main()
    int i = 1, num, sum = 0;
    printf(" Enter the number:");
    scanf("%d", &num);
    while (i < num)
        if (num % i == 0)
            sum = sum + i;
    if (sum == num)
        printf("%d is Perfect Number\n", num);
        printf("%d is not a Perfect Number\n", num);
$ gcc perfect.c
$ ./a.out
Enter the number:6
6 is Perfect Number
$ ./a.out
Enter the number:100
100 is not a Perfect Number

If you like the post C program to C program to Check if a Number is Perfect or Not please share your feedback!

also see

C Programming language
Go Programming language
Linked List Array
Simplification Queue
DBMS Reasoning
Aptitude HTML
Previous articleQueue Implementation using Array
Next articleSPPU FY B.SC ( COMPUTER SCIENCE ) 2013 PATTERN Question Bank


Please enter your comment!
Please enter your name here