Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Perfect Numbers in a Range in C-Language



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
#include
int perfect(int x)
{
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");
}






Don't just read, write it, run it.....

RESULT:color>






This post first appeared on ProgramJoy.blogspot.com, please read the originial post: here

Share the post

Perfect Numbers in a Range in C-Language

×

Subscribe to Programjoy.blogspot.com

Get updates delivered right to your inbox!

Thank you for your subscription

×