문제 출처: www.acmicpc.net/problem/1330
1330번: 두 수 비교하기
두 정수 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 A, B; | |
cin >> A >> B; | |
if (A > B) | |
cout << ">"; | |
else if (A < B) | |
cout << "<"; | |
else | |
cout << "=="; | |
return 0; | |
} |
2. 풀이
int A, B;
cin >> A >> B;
A와 B 변수를 선언 후 값을 입력하여 초기화한다.
if (A > B)
cout << ">";
A의 값이 B보다 크다면 >를 출력하게 한다.
else if (A < B)
cout << "<";
만약 그렇지 않다면 A의 크기가 B보다 작다면 <를 출력하게 된다.
else
cout << "==";
만약 위 조건 중 모두 해당되지 않는다면 ==을 출력하게 된다.
'컴퓨터 > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 14681번: 사분면 고르기 [C++] (0) | 2020.11.27 |
---|---|
백준 알고리즘 9498번: 시험 성적 [C++] (0) | 2020.11.24 |
백준 알고리즘 2588번: 곱셈 [C++] (0) | 2020.11.22 |
백준 알고리즘 10430번: 나머지 [C++] (0) | 2020.11.21 |
백준 알고리즘 10869번: 사칙연산 [C++] (0) | 2020.11.20 |