#include // Query the user for one positive integer 'm' // and draw an inverted triangle of asterisks // with 'm' rows. // // The first row contains 2*m - 1 asterisks. // Each subsequent row begins with one additional // space and contains two fewer asterisks. // // For example, if m = 5, the output should be // // ^ ********* // | ******* // 5 ***** // | *** // v * // // If the user enters a value for 'm' that is not // positive, simply return 0. // Function declarations int main(); // Function definitions int main() { return 0; } // Hint: // // Like the previous exercise, we must print 'm' // rows, so the outer loop will look like: // // for ( int row{ 1 }; row <= m; ++row ) { // // // Print the appropriate number of spaces. // // // Print the appropriate number of asterisks. // // std::cout << std::endl; // } // // Again, each row requires two inner loops. The // first prints the spaces before the asterisks, // and the second prints the asterisks. // // How many spaces and asterisks should be printed // on each row? // The value of 'row' controls both the number of // spaces and the number of asterisks. // // For example, if m = 5: // // row spaces asterisks // 1 1 - 1 9 // 2 2 - 1 7 // 3 3 - 1 5 // 4 4 - 1 3 // 5 5 - 1 1 // // Thus, the number of spaces is simply // // row - 1. // // The number of asterisks begins at 2*m - 1 and // decreases by 2 each time 'row' increases by 1. // // What formula involving 'm' and 'row' produces // the values // // 2*m - 1, 2*m - 3, 2*m - 5, ..., 1? // One formula for the number of asterisks is // // 2*m - 2*row + 1, // // which can also be written as // // 2*(m - row) + 1. // // Check this when m = 5: // // row = 1: 2*(5 - 1) + 1 = 9 // row = 2: 2*(5 - 2) + 1 = 7 // row = 3: 2*(5 - 3) + 1 = 5 // row = 4: 2*(5 - 4) + 1 = 3 // row = 5: 2*(5 - 5) + 1 = 1 // Here is one solution: /* int main() { int m{}; std::cout << "Enter a positive integer 'm': "; std::cin >> m; if ( m <= 0 ) { return 0; } for ( int row{ 1 }; row <= m; ++row ) { // Print the spaces preceding the asterisks. for ( int column{ 1 }; column <= row - 1; ++column ) { std::cout << " "; } // Print the asterisks. for ( int column{ 1 }; column <= 2*(m - row) + 1; ++column ) { std::cout << "*"; } // The current row is complete. std::cout << std::endl; } return 0; } */