프로그래밍언어/알고리즘
백준 2738 행렬 덧셈_JAVA
새끼개발자
2023. 9. 19. 15:43
https://www.acmicpc.net/problem/2738
2738번: 행렬 덧셈
첫째 줄에 행렬의 크기 N 과 M이 주어진다. 둘째 줄부터 N개의 줄에 행렬 A의 원소 M개가 차례대로 주어진다. 이어서 N개의 줄에 행렬 B의 원소 M개가 차례대로 주어진다. N과 M은 100보다 작거나 같
www.acmicpc.net
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int [][] arr1 = new int[N][M];
int [][] arr2 = new int[N][M];
for (int i = 0 ; i < N ; i++) {
for(int j = 0 ; j < M ; j++)
arr1[i][j] = sc.nextInt();
}
for (int i = 0 ; i < N ; i++) {
for(int j = 0 ; j < M ; j++) {
arr2[i][j] = sc.nextInt();
System.out.print(arr1[i][j] + arr2[i][j] + " ");
}
System.out.println();
}
}
}