Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- bool isarmstrong(int i) {
- int zbytek = 0;
- int suma = 0;
- int delenec = i;
- while(delenec != 0) {
- zbytek = delenec % 10;
- delenec /= 10;
- suma += pow((float)zbytek, (int)3);
- }
- if(suma == i)
- return true;
- return false;
- }
- int main() {
- int upperbound = 0;
- std::cin >> upperbound;
- int i = 1;
- while(i <= upperbound) {
- if(isarmstrong(i)) {
- std::cout << i << " ";
- }
- i++;
- }
- std::cin.get();
- std::cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment