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

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**C++ Program To Find Prime Numbers*#include<iostream.h> #include<math.h> int main() { int i,n,sum=0; cout<<"enter a number"; cin>>n; for (i=1;i<n;i++) { if(n%i==0) sum=sum+i; } if(sum==n) cout<<i<<"is a perfect number"; else cout<<i<<"is not a perfect number"; return 0; }

Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:

HTML Link Code:

BB (forum) link code:

## Comments

## Post a Comment

Please share your views on this topic with Grace Joseph by leaving a comment.