How to Find Perfect Number in C++.


There is Some Logical code of Perfect Number you can change number that you need range from number. Perfect number is that number which divisor is equal to proper itself.

Program:

#include<iostream>
#include<conio>
void main()
{
int i=1, u=1, sum=0;
while(i<=500)
{
while(u<=500)
{
if(u<i)
{
if(i%u==0 )
sum=sum+u;
}
u++;
}
if(sum==i)
{
cout<<i<<" is a perfect number."<<"\n";
}
i++;
u=1;  sum=0;
}
getch();
}
output Result:


Post a Comment

Total Pageviews