Well, a perfect no. is a no. whose sum of its divisor except the no. itself is the given number (Eg. 6=1+2+3)(Eg.28=1+2+4+7+14)
I know the logic of finding perfect no. as shown below:::
#include <iostream.h>
#include <math.h>
#include <conio.h>
void main()
{
long i,j,n,sum=0;
clrscr();
cout<<"Enter number";
cin>>n;
for(i=1;i<=n/2;i++)
{
if(n%i==0)
{
sum=sum+i;
}
}
if(sum==n)
cout<<"No. is perfect";
else
cout<<"Not perfect!!!";
}
BUT i m unable to convert it for given n numbers.
suppose n>=29<=495
o/p must be 6 28
if n=497
o/p must be 6 28 496
pls help me.
how do i convert it?
Just loop till you get to whatever the maximum is...(for loop!!)
thats correct...
but problem is ... than n%i==0 wont be true...suppose n=29...obviously, n%i will never become zero...plz see that condition.
Filter out the primes before the test for perfection.
I'll leave you to figure out how.