#include // Write a program that queries the user for an // integer and prints up to the five largest powers // of 10 that are less than or equal to that integer. // // For example, given // // 532098253 // // print // // 100000000 10000000 1000000 100000 10000 // // Given // // 153 // // print // // 100 10 1 // // Given any integer less than or equal to 0, print // nothing. // Function declarations int main(); // Function definitions int main() { return 0; } // Hint: // // There are two parts to this problem: // // 1. Find the largest power of 10 that is less // than or equal to the integer entered by the // user. // // 2. Starting with that power of 10, print up to // five powers of 10, stopping early if you // reach 1. // // You can use either while loops or for loops, and // you may find a break statement useful. // // Try this as much as you can on your own before // looking at the solution. You may find a completely // different, but equally valid, approach. // Hint: // // Start with // // int power{ 1 }; // // How could you repeatedly multiply 'power' by 10 // until doing so would make it greater than 'n'? // // Be careful with an expression such as // // 10*power <= n. // // If 'power' becomes sufficiently large, the // multiplication by 10 could overflow. // // Since n is positive, can you rewrite the condition // using integer division so that no multiplication // by 10 is required? // There are many solutions to this problem. // // Here is one solution: /* int main() { int n{}; std::cout << "Enter an integer: "; std::cin >> n; if ( n <= 0 ) { return 0; } int power{ 1 }; // Find the largest power of 10 that is less // than or equal to n. while ( power <= n/10 ) { power *= 10; } // Print at most five powers of 10. for ( int k{ 0 }; k < 5; ++k ) { std::cout << power; if ( power == 1 ) { break; } std::cout << " "; power /= 10; } std::cout << std::endl; return 0; } */