Could you please show me how do we use the loop assignment i

Could you please show me how do we use the loop assignment in this exercise from the given information and how did they do the program
AT&T; 3:00 PM 100% Done Exam1-Solutions.pdf 2) Write a program that will output the pattern shown below, using two nested for loops. The number of rows n in the pattern should be entered by the user via keyboard. In the Figure below n 7. Notice that there is only one space between 2 and 2. Solution 14 points There are several slightlydifferent ways to solve this problem. However, the program will always consist of a couple nested loops as shown below. dinclude

Solution

This is one of the easy code for the above problem. try to loop dry run this program. #include using namespace std; int main() { int n; cin >> n; int size = 2 * n - 1; int mid = (size - 1) / 2; int x = 1; for (int i = 0; i < size; i++) { if (i == mid) cout << x++; else { cout << \" \"; } } cout << endl; int p = mid - 1, q = mid + 1; int flag = 0; for (int i = 0; i < size - 2; i++) { for (int j = 0; j < size; j++) { if (p == j || q == j) cout << x; else cout << \" \"; } if (p == 0) { flag = 1; } if (flag == 1) { p++; q--; x--; } else { p--; q++; x++; } cout << endl; } for (int i = 0; i < size; i++) { if (i == mid) cout << \"1\"; else { cout << \" \"; } } }
Could you please show me how do we use the loop assignment in this exercise from the given information and how did they do the program AT&T; 3:00 PM 100% Do

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site