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.
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
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 : :
OUTPUT : :
need an explanation for this answer? contact us directly to get an explanation for this answer