Question: You are provided with the number of rows (R) and columns (C). Your task is to generate the matrix having R rows and C columns

You are provided with the number of rows (R) and columns (C). Your task is to generate the matrix having R rows and C columns such that all the numbers are in increasing order starting from 1 in row wise manner.

Input Format: The first line contain two numbers R and C separated by a space.

Output Format: Print the elements of the matrix with each row in a new line and elements of each row are separated by a space.

NOTE: There should not be any space after the last element of each row and no new line after the last row.

Example:

Input:

3 3

Output:

1 2 3

4 5 6

7 8 9

I have tried the following code. It runs on the online compiler. But shows an error in some compilers , in the output. I want to remove this error

x=[]

a=[int(n) for n in input().split()]

#print(*a)

for i in range(a[0]):

    x.append(list(map(int, input().rstrip().split())))

for i in range(a[0]):

    for j in range(a[1]):

        print(x[i][j], end = " ")

    print()

Desired output on new lines

1 2 3

4 5 6

Actual output

1 2 3

4 5 6

Step by Step Solution

3.52 Rating (149 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This script will take input in the form of li... View full answer

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 Banking Questions!