In this C-program we will check the Perfect numbers in a given Range and print them on the screen. The lower range and the upper range will be taken from the user.color>
input:
The Lower Range and the Upper Range.output:
The Perfect numbers will be printed on the screen in the given range.CODE---->
#include
int perfect(int x)
#include
{
int i,sum=0;
if(x==0)
return 0;
for(i=1;ix-1);i++)
{
if(x%i==0)
sum=sum+i;
}
if(sum==x)
return 1;
else
return 0;
}
int main()
{
int num,i,lr,ur,check;
printf("\n Please, Enter the Lower range : ");
scanf("%d",&lr);
printf("\n Please, Enter the Higher range : ");
scanf("%d",&ur);
printf("\n The Perfect Numbers are : ");
for(i=lr;iur;i++)
{
check=perfect(i);
if(check==1)
printf(" %d ",i);
}
printf("\n");
}