Read the input matrix into a two-dimensional array. Then print it.
Algorithm Implementation
Declare a two-dimensional array.
int a[101][101];Read the sizes of the array and .
scanf("%d %d", &n, &m);Read the input array.
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
scanf("%d", &a[i][j]);Print the array.
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
printf("%d ", a[i][j]);
printf("\n");
}Java Implementation
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner con = new Scanner(System.in);
int n = con.nextInt();
int m = con.nextInt();
int a[][] = new int[n+1][m+1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
a[i][j] = con.nextInt();
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
}Python Implementation
Read the sizes of the array and .
n, m = map(int,input().split())Read the input array.
a = [[] for i in range(n)]
for i in range(n):
a[i] = list(map(int, input().split()))Print the array.
for i in range(n):
for j in range(m):
print(a[i][j],end = " ")
print()Python Implementation — Second Solution
Read the input data.
n, m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]Print the array.
for row in a:
print(*row)Python Implementation — Third Solution
Read the input data.
n, m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]Print the array.
for _ in a:
for x in _:
print(x,end=" ")
print()