//program illustrates use of nested loops to print a pattern of characters //as an inverted triangle //Author: Carol Conway revised 10/2/2018 #include using namespace std; int main() { char ch; //the fill character int maxRowWidth; //the maximum width of the inverted triangle cout << "Enter character for pattern "; ch = cin.get(); cout << "Enter the maximum width of the the triangle \n"; cout << "This must be an odd number from 3 through 79 "; cin >> maxRowWidth; //input validation loop while (maxRowWidth < 3 or maxRowWidth > 79) { cout << "Enter an odd number (from 3 up to 79) "; cin >> maxRowWidth; } //make sure number of rows is odd by adding one to any even input value if (maxRowWidth % 2 == 0) maxRowWidth++; //outer loop controls output of the rows in the figure for (int i = 1; i <= maxRowWidth/2+ 1; i++) // i is the current row number { //nested loop controls indentation by printing spaces for (int k = 1; k < i; k++) cout << " "; //nested loop controls printing one row of characters for (int j = 1; j < maxRowWidth-2*(i-1)+1;j++) //j is the column position cout << ch; cout << endl; } return 1; }