Program-1

The matrix has R rows and C columns. Write a program to generate a matrix having R rows and C columns such that all the numbers are in increasing order starting from the number 1 and in a row-wise

r,c=map(int,input("Enter the number of rows and colums: ").split())
x=1

mat=[[0 for j in range(c)]for i in range(r)]
for i in range(r):
for j in range(c):
mat[i][j]=x
x=x+1

for i in range(r):
for j in range(c):
print(mat[i][j],end=" ")
print()

Enter the number of rows and colums: 3 3
1 2 3
4 5 6
7 8 9 

No comments:

Post a Comment