문제 출처: www.acmicpc.net/problem/10950
10950번: A+B - 3
두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
1. 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
int t; | |
cin >> t; | |
for(int i = 0; i < t; i++) | |
{ | |
int a, b; | |
cin >> a >> b; | |
cout << a + b << endl; | |
} | |
return 0; | |
} |
2. 풀이
int t;
cin >> t;
먼저 t에 대한 값을 입력받는다.
for(int i = 0; i < t; i++)
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
}
그리고 t만큼 반복하여 수를 a와 b를 입력해야 하기 때문에 i를 선언 후 for 문을 이용하여 반복시켜주고, a와 b를 입력 후 a + b의 값을 출력해준다.
return 0;
그리고 종료시켜주면 된다.
'컴퓨터 > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 15552번: 빠른 A+B [C++] (0) | 2020.12.04 |
---|---|
백준 알고리즘 8393번: 합 [C++][재귀] (0) | 2020.12.03 |
백준 알고리즘 2739번: 구구단 [C++] (0) | 2020.11.30 |
백준 알고리즘 2884번: 알람 시계 [C++] (0) | 2020.11.29 |
백준 알고리즘 14681번: 사분면 고르기 [C++] (0) | 2020.11.27 |