Program to find the perfect numbers below a given number.

The program is to find all the perfect numbers in the range, which starts from zero and ends at user defined limit. A perfect number is a one, whose sum of devisors is equals the number itself.

Logic: This is a slightly modified version of the previous program. Here, user need to enter the number as the upper limit for the for the iteration loop to find the perfect number The outer for loop traces the iteration till the limit,, wherein each of iteration inner for loop checks the present number is perfect or not, with the previous program’s logic. If it is, it prints out the present number.

In this program, the lower limit is constant zero. We can change that also, to make the program fully flexible, and to print out all the perfect number between the given range.

Program to find the perfect numbers below a given number.

#include<stdio.h>
#include<math.h>
void main()
{
int i,n,sum,lim;
clrscr();
printf(“\n\n\t ENTER THE UPPER LIMIT…: “);
scanf(“%d”,&lim);
printf(“\n\n\t THE PERFECT NUMBER ARE..:”);
for(n=1;n<lim;n++)
{
sum = 0;
for(i=1;i<n;i++)
if(n%i == 0)
sum = sum + i;
if (sum == n)
printf(“\n\n\t\t\t%d”,n);
}
getch();
}
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.

    StudentProjects.in