//File patterns.cpp //Author: Carol Conway 3/27/18 //This program illustrates the use of loops to print various patterns #include using namespace std; int main() { int rows; //number of rows desired in the pattern cout << "How many rows would you like to display? \n"; cout << "You may enter a number from 1 to 25 "; cin >> rows; while (rows < 3 || rows > 25) { cout << "Rows must be from 3 to 25. Try again! "; cin >> rows; } cout << "This is a square pattern\n"; for (int j = 1; j <= rows; j++) { for (int k = 1; k <= rows; k++) { cout << "*"; } cout << "\n"; //end of a row } cout << "This is a triangle pattern\n"; for (int j = 1; j <= rows; j++) { for (int k = 1; k <= j; k++) { cout << "*"; } cout << "\n"; //end of a row } cout << "This is an indented right triangle pattern\n"; //It only works it the number of rows is odd if (rows %2 == 0) rows++; for (int j = 1; j <= rows; j++) { //writes the spaces for (int i = rows -j; i > 0; i-- ) cout << " "; //writes the stars for (int k = 1; k <= j; k++) cout << "*"; cout << "\n"; //end of a row } cout << "This is an indented triangle pattern\n"; //It only works it the number of rows is odd if (rows %2 == 0) rows++; for (int j = 1; j <= rows; j++) { //writes the spaces for (int i = rows -j; i > 0; i-- ) cout << " "; //write the stars for (int k = 1; k <= 2*j-1; k++) cout << "*"; cout << "\n"; //end of a row } return 1; }