Post Top Ad

Your Ad Spot

Pages

Sunday, 9 February 2020

Display Nth Perfect number

#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 IsPerfectNth(int n)
{
int i,c=0; 
if(n>=5)
{
printf("NO PERFECT NO IN %d position",n);
}
else{
for(i=1;c<n;i++)
{
if(IsPerfect(i))

   c++;
}
}
printf("%d",i-1);

}
}

 void main()
{         
  IsPerfectNth(5);
}

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages