Answer to Question #193277 in C++ for Sarivinkumar M

Question #193277

Create a class Armstrong and include startnumber and endnumber as data member and aslo include member function findArmstrongNumbers() to find all the Armstrong numbers between startnumber and endnumber. If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number

Run time input 1and 500


1
Expert's answer
2021-05-15T13:53:53-0400
#include <iostream>
 
using namespace std;
 
class Armstrong
{
public:
	Armstrong(int start, int end);
	void Find();
private:
	int startNumber;
	int endNumber;
};
 
Armstrong::Armstrong(int start, int end) : startNumber(start), endNumber(end)
{}
 
void Armstrong::Find()
{
	for (int i = startNumber; i <= endNumber; i++)
	{
		int temp = i;
		int sum = 0;
		while (true)
		{
			if (temp < 10)
			{
				sum += (temp % 10) * (temp % 10) * (temp % 10);
				break;
			}
			sum += (temp % 10) * (temp % 10) * (temp % 10);
			temp /= 10;
		}
		if (sum == i)
		{
			cout << i << " is Armstrong number!" << endl;
		}
 
	}
}
 
int main()
{
	int start, end;
	cout << "Enter start number: ";
	cin >> start;
	cout << "Enter end number: ";
	cin >> end;
	Armstrong obj(start, end);
	obj.Find();
	cout << endl;
	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