Post Top Ad

Your Ad Spot

Pages

Sunday 9 February 2020

Display All Perfect Number From A to B

#include<stdio.h>
#include<conio.h>
// Check perfect no por not
int IsPerfect(int no)
{
int i,res=0;
for(i=1;i<=no/2;i++)
{
if(no%i==0)
{
res=res+i;
}
}
return res==no;
}
void IsPerfectAtoB(int a,int b)
{
int i;
for(i=a;i<=b;i++)
{
if(IsPerfect(i))
printf(" %d",i);
}

}

 void main()
{         
  IsPerfectAtoB(5,10000);
}

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages