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

Question #193428

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.

Runtime input

1

500


1
Expert's answer
2021-05-18T07:23:56-0400
#include <iostream>
using namespace std;




class Armstrong{
	int startnumber;
	int endnumber;
public:


	Armstrong(int sn , int en){
		startnumber = sn;
		endnumber = en;       
	}
	void findArmstrongNumbers(){
		for(int number = startnumber; number <= endnumber; number++){
			int sum = 0;
			int temp = number;
			while(temp > 0)  {    
				int d = temp%10;    
				sum += d*d*d;    
				temp /= 10;    
			}
			if(number == sum) {
				cout<<number<<"\n";
			}   
				
		}
	}
};
int main(){
	
	int startnumber;
	int endnumber;


	cout<<"Input start number: ";
	cin>>startnumber;
	cout<<"Input end number: ";
	cin>>endnumber;
	Armstrong armstrongChecker(startnumber, endnumber);
	armstrongChecker.findArmstrongNumbers();


	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