Answer to Question #299786 in C++ for Nancy

Question #299786

Write a program in C++ to input 10 numbers and print only abundant numbers.



An abundant number is the number for which the sum of its proper divisors(excluding the



number itself) is greater than the original number.



Sample input: 12



Sample output:



Its proper divisors are 1, 2, 3, 4 and 6



Sum = 1 + 2 + 3 + 4 + 6 =16



Hence 12 is an abundant number.

1
Expert's answer
2022-02-20T14:40:58-0500




#include <iostream>


using namespace std;




bool isAbundantNumber(int number){
	int sumDivisors=0;
	for(int i=1;i<number;++i)
	{
		if(number%i==0){
			sumDivisors+=i;
		}
	}
	return (sumDivisors>number);
}




int main() {
	for(int i=0;i<10;i++){
		int number;
		cout<<"Enter number: ";
		cin>>number;
		if(isAbundantNumber(number)){
			cout<<number<<" is an abundant number.\n";
		}


	}


	system("pause");
	return 0;
}

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