Find The Perfect Number In C++ Program andrey вторник, 30 сентября 2014 г. No Comment

C++ program to find if a number is a perfect number or not. A Perfect number is one which the sum of all its divisors equals to the number.
For example 28 a Perfect Number since the sum of its divisors which are 1+ 2 + 4 + 7 + 14 = 28

Also Read: C++ Program To Find Roots Of a Quadratic Equation

#include
#include
int main()
{
int i,n,sum=0;
cout<<"enter a number";
cin>>n;
for (i=1;i {
if(n%i==0)
sum=sum+i;
}
if(sum==n)
cout<"is a perfect number";
else
cout<"is not a perfect number";
return 0;
}

Also Read: C++ Program To Find Prime Numbers
C++ program to find if a number is a perfect number or not. A Perfect number is one which the sum of all its divisors equals to the number.
For example 28 a Perfect Number since the sum of its divisors which are 1+ 2 + 4 + 7 + 14 = 28

Also Read: C++ Program To Find Roots Of a Quadratic Equation

#include
#include
int main()
{
int i,n,sum=0;
cout<<"enter a number";
cin>>n;
for (i=1;i {
if(n%i==0)
sum=sum+i;
}
if(sum==n)
cout<"is a perfect number";
else
cout<"is not a perfect number";
return 0;
}

Also Read: C++ Program To Find Prime Numbers
by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment