Question: Please write a c++ program and generate the output as the same as below. Matrix Given a positive integer n , please generate an upper

Please write a c++ program and generate the output as the same as below.

Matrix

Given a positive integer n, please generate an upper triangular (e.g., all the entries below the main diagonal are empty) matrix of size n (i.e., the number of both rows and columns equals to n), filled with the numbers from 1 to (n + 5) n/2 in the following repeated order:

the direction of the numbers increasing is from left to right in the first row,

from right to left in the second row,

from left to right in the third row,

Three examples are shown follows.

In this question, we assume the input n is valid, i.e., you do not need to check its correctness.

We assume n is not very large, e.g., n < 50.

Two adjacent numbers on the same row are separated by a tab character.

No space or tab before 1 in the first row

No space or tab between two rows

Example-1:

Input: 3

1 2 3

5 4

6

Example-2:

Input: 2

1 2

3

Example-3:

Input: 4

1 2 3 4

7 6 5

8 9

10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!