# C++ program to find perfect number

Learn: What is perfect number? How to check whether a given number is perfect number of not?
Submitted by Manu Jemini, on September 28, 2017

Given an integer number and we have to check whether it is perfect number or not?

This C++ program is used to find the perfect number of a positive number and find its all positive divisors excluding that number.

Explanation: For Example, 6 is a perfect number since divisors of 6 are 1, 2, and 3, then sum of its divisor is 1 + 2 + 3 = 6.

Note: A perfect number is a positive integer that is equal to the sum of its proper positive divisors.

Consider the program:

```#include <iostream>
using namespace std;

int main()
{
int n,i=1,sum=0;

cout<<"Enter a number: ";
cin>>n;
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}

if(sum==n)
cout << i << " is a perfect number\n";
else
cout << i << " is not a perfect number\n";

return 0;
}
```

Output

```Enter a number: 6
6 is a perfect number
```

Top MCQs

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates