728x90
https://www.acmicpc.net/problem/2738
2738번: 행렬 덧셈
첫째 줄에 행렬의 크기 N 과 M이 주어진다. 둘째 줄부터 N개의 줄에 행렬 A의 원소 M개가 차례대로 주어진다. 이어서 N개의 줄에 행렬 B의 원소 M개가 차례대로 주어진다. N과 M은 100보다 작거나 같
www.acmicpc.net
using System;
namespace Baekjoon
{
class Program
{
static void Main(string[] args)
{
string[] s = Console.ReadLine().Split();
int n = int.Parse(s[0]);
int m = int.Parse(s[1]);
int[,] A = new int[n, m];
int[,] B = new int[n, m];
//행렬 A
for(int row = 0; row < n; row++)
{
string[] line = Console.ReadLine().Split();
for(int col = 0; col < m; col++)
A[row, col] = int.Parse(line[col]);
}
//행렬 B
for(int row = 0; row < n; row++)
{
string[] line = Console.ReadLine().Split();
for (int col = 0; col < m; col++)
B[row, col] = int.Parse(line[col]);
}
//덧셈
for(int row = 0; row < n; row++)
{
for(int col = 0; col < m; col++)
Console.Write(A[row, col] + B[row, col] + " ");
Console.WriteLine(); //줄 바꿈
}
}
}
}
728x90
'Programming Practice > C#' 카테고리의 다른 글
백준 3003 킹, 퀸, 룩, 비숍, 나이트, 폰 C# (0) | 2023.09.16 |
---|---|
백준 2744 대소문자 바꾸기 C# (0) | 2023.09.10 |
C# 기본2 (0) | 2022.11.16 |
C# 기본 (0) | 2022.11.16 |