You are provided with the number of rows (R) and columns (C). Your task is to generate
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 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
Social Statistics for a Diverse Society
ISBN: 978-1483333540
7th edition
Authors: Chava Frankfort-Nachmias, Anna Leon-Guerrero