#include // Query the user for one non-negative integer 'm' // and draw the pattern shown below. // // If m = 5, the output should be // // ************************* // **************** // ********* // **** // * // // * // **** // ********* // **************** // ************************* // // If m = 6, the output should be // // ************************************ // ************************* // **************** // ********* // **** // * // // * // **** // ********* // **************** // ************************* // ************************************ // // Notice that the numbers of asterisks are // perfect squares. For m = 5, they are // // 25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25. // // If m = 0, print one blank line. // // If m = 1, print // // * // // * // // If the user enters a negative value, simply // return 0. // Function declarations int main(); // Function definitions int main() { return 0; } // Hint: // // The number of asterisks on each row follows // a quadratic pattern: // // 2 2 2 2 2 2 2 2 2 // m , ..., 3 , 2 , 1 , 0 , 1 , 2 , 3 , ..., m // // Can you choose a loop variable whose values // range from -m through m? // // If so, how many asterisks should be printed // when that loop variable has the value 'row'? // // Can you solve the entire problem using only // one loop nested inside another loop? // Suppose the outer loop variable 'row' takes // the values // // -m, ..., -3, -2, -1, 0, 1, 2, 3, ..., m. // // The number of asterisks to print is // // 2 // row . // // There is no need to treat negative values // differently because, for example, // // 2 2 // (-3) = (3) = 9. // // What happens when row == 0? // // The inner loop executes zero times, but the // newline is still printed. Thus, the blank // line in the middle appears automatically. // Here is one solution: /* int main() { int m{}; std::cout << "Enter a non-negative integer 'm': "; std::cin >> m; if ( m < 0 ) { return 0; } for ( int row{ -m }; row <= m; ++row ) { for ( int column{ 1 }; column <= row*row; ++column ) { std::cout << "*"; } std::cout << std::endl; } return 0; } */