Perfect Number

#include<iostream>
using namespace std;

int main() {
	int no, i = 1, sum = 0;
	
	/* 'endl' insert linefeed like '\n' */
	cout << "Check the given number is Perfect Number or not" << endl;
	cout << "Enter a number:" << endl;
	cin >> no;

	/* Loop the process using "while loop" */
	while(i < no) {
		if(no % i == 0)
			sum += i;
		i++;
	}

	if(sum == no)
		cout << no << " is a Perfect Number!" << endl;
	else
		cout << no << " is not a Perfect Number!" << endl;

	return 0;
}


/* Output */
/* Check the given number is Perfect Number or not
Enter a number:
6

6 is a Perfect Number!
*/


/* ------------------------------- */


/*
Check the given number is Perfect Number or not
Enter a number:
14

14 is not a Perfect Number! */
                                Copy Code