Program for perfect numbers

Here is a program to find whether the entered number is a perfect or not. A perfect number is a one, whose sum of devisors is equals the number itself.

Logic: Here in the program, user need to enter the number to check if it is perfect. The for loop in the program traces the iteration till the number, while in each of iteration it checks the present number is the divisor of the entered or not. If it is, it adds it to the flag, which holds the sum of all the divisors. Finally, it checks if the sum equals the given number.

The same algorithm is modified slightly, and developed a program to print all the perfect number till the user defined range.

Program to find whether a number is a perfect or not

void main()
int i ,n, sum = 0;
printf(“\n\n\t ENTER A NUMBER…: “);
scanf(“%d”, &n);
for(i=1; i<n; i++)
if(n%i == 0)
sum = sum + i;
if(sum == n)
printf(“\n\n\t THE NUMBER %d IS A PERFECT NUMBER”, n);
printf(“\n\n\t THE NUMBER %d IS NOT A PERFECT NUMBER”, n);

Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.