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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
class Armstrong {
private:
int startnumber;
int endnumber;
public:
Armstrong(int start, int end);
~Armstrong();
void findArmstrongNumbers();
};
Armstrong::Armstrong(int start, int end) {
this->startnumber = start;
this->endnumber = end;
}
Armstrong::~Armstrong() {}
void Armstrong::findArmstrongNumbers() {
cout << "\nAll the Armstrong numbers between your integers are: \n";
for (int i = startnumber; i <= endnumber; ++i) {
int x = i;
int n = 0;
while (x != 0) {
x /= 10;
++n;
}
int powSum = 0;
x = i;
while (x != 0) {
int digit = x % 10;
powSum += pow(digit, n);
x /= 10;
}
if (powSum == i) {
cout << i << "\n";
}
}
}
int main(){
int start;
int end;
cout << "Hello! This program allows you to find all the Armstrong numbers between two integers.\n\n";
cout << "Please enter the start number: ";
cin >> start;
cout << "Please enter the end number: ";
cin >> end;
Armstrong armstrong(start, end);
armstrong.findArmstrongNumbers();
return 0;
}
Comments
Dear Sarivinkumar M please post a new task
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
Leave a comment