63 213
Assignments Done
99,3%
Successfully Done
In July 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions