Post Top Ad

Your Ad Spot

Pages

Sunday, 9 February 2020

Display All Perfect Number Up To N

#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 IsPerfectTn(int n)
{
int i;
for(i=1;i<=n;i++)
{
if(IsPerfect(i))
printf(" %d",i);
}

}

 void main()
{         
  IsPerfectTn(500);
}

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages