Answer to Question #53233 in C++ for shahzad raza

Question #53233
write a program that inputs a number from the user and displays all armstrong number up to the number entered.
1
Expert's answer
2015-07-07T03:45:22-0400
#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main(){
int armstrongNumbers;
cout << "Hi! Enter N?\n";
cin >> armstrongNumbers;
int q1 = 10000, q2 = 1000, q3 = 100, q4 = 10;
vector<int> a(1);
for (int i = 0; i < armstrongNumbers; i++){
int armN = 0;
for (int j = 0; j < a.size(); j++){
armN += pow(a[j], a.size());
}
if (i == armN) cout << armN << endl;

int k = 0;
a[k]++;
while (a[k]>9) {
if (k + 1 >= a.size()) a.push_back(0);
a[++k] += a[k - 1] / 10;
a[k - 1] = a[k - 1] % 10;
}
}

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
APPROVED BY CLIENTS