#include // Query the user for one positive integer 'm' // and draw a right-aligned triangle of asterisks // with 'm' rows. // // The first row contains one asterisk, the second // row contains two asterisks, and so on, with the // final row containing 'm' asterisks. Add spaces // before the asterisks so that the right edge of // the triangle is aligned. // // 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; // } // // This time, however, 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 5 - 1 1 // 2 5 - 2 2 // 3 5 - 3 3 // 4 5 - 4 4 // 5 5 - 5 5 // // More generally, on each row: // // number of spaces = m - row // number of asterisks = row // // Therefore, inside the outer loop, use one loop // to print 'm - row' spaces followed by another // loop to print 'row' asterisks. // // The two inner loops may use the same loop-variable // name because the variable declared in each for // loop exists only within that loop. // 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 <= m - row; ++column ) { std::cout << " "; } // Print the asterisks. for ( int column{ 1 }; column <= row; ++column ) { std::cout << "*"; } // The current row is complete. std::cout << std::endl; } return 0; } */