Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

This script will take input in the form of li... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Social Statistics For A Diverse Society

Authors: Chava Frankfort Nachmias, Anna Leon Guerrero

7th Edition

148333354X, 978-1506352060, 1506352065, 978-1483359687, 1483359689, 978-1483333540

More Books

Students also viewed these Banking questions