Perfect Numbers in Given Range Program

This Perfect Numbers in Given Range using C language explains: A perfect number is a positive integer.The perfect number is equal to the sum of its proper positive divisors excluding the number itself. It is also known as its aliquot sum.


#include<stdio.h>
void main()
{
int limit, n, i, sum;
printf(“Enter limit : “);
scanf(“%d”, &limit);

for(n=1 ; n<=limit ; n++)
{
sum=0 ;
for(i=1 ; i<n ; i++)
{
if(n%i == 0)
{
sum = sum + i ;
}
}
if(n==sum)
{
printf(“%d is Perfect number \n”, n);
}
}
}

Share this