Answer to Question #345234 in C++ for Ali

Question #345234

Input a positive integer from the user and determine whether the number is a perfect number or not.


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


sum of its positive divisors excluding the number itself.

1
Expert's answer
2022-05-26T09:14:02-0400
#include <iostream>

using namespace std;

int main()
{
	int num;
	cout << "Please, enter a number to check: ";
	cin >> num;
	int sum=0;
	for (int i = 1; i < num; i++)
	{
		int d = num%i;
		if (d == 0)
			sum += i;
	}
	if (sum == num)
		cout << num << " is a perfect number";
	else
		cout << num << " is not a perfect number";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS