Q:

Write a C Program to find the perfect numbers below a given number

0

Write a C Program to find the perfect numbers below a given number. Here’s simple C Program to find the perfect numbers below a given number in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Numbers in C


Normally, when we work with Numbers, we use primitive data types such as int, short, long, float and double, etc. The number data types, their possible values and number ranges have been explained while discussing C++ Data Types.


Perfect number : :


A perfect numbers is a positive number that equals the sum of its divisors, excluding itself. This is also known as its aliquot sum. At this time, it is unknown how many perfect numbers truly exist in our number system.

While we have discovered 48 perfect numbers, the fact that there are an infinite number of prime numbers leads us to believe that there could be an infinite number of perfect numbers.


Here is source code of the C Program to find the perfect numbers below a given number. The C program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.


SOURCE CODE : :

// C Program to find the perfect number below a given number


#include<stdio.h>
#include<math.h>
int main()
{
int i,n,sum,lim;

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);
}
return 0;
}

OUTPUT : :


*************** OUTPUT **************


      ENTER THE UPPER LIMIT: 10000


         THE PERFECT NUMBER ARE..:

                        6

                        28

                        496

                        8128

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Number Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to Generate Fibonacci Series using while... >>
<< C Program to Find all Prime Numbers less than N...