티스토리 뷰

문제

두 정수 A와 B가 주어졌을 때, A와 B를 비교하는 프로그램을 작성하시오.

입력

첫째 줄에 A와 B가 주어진다. A와 B는 공백 한 칸으로 구분되어져 있다.

출력

첫째 줄에 다음 세 가지 중 하나를 출력한다.

  • A가 B보다 큰 경우에는 '>'를 출력한다.
  • A가 B보다 작은 경우에는 '<'를 출력한다.
  • A와 B가 같은 경우에는 '=='를 출력한다.

제한

  • -10,000 ≤ A, B ≤ 10,000

풀이 과정

조건문을 사용하여 A와 B의 값에 따른 올바른 결과를 출력한다.

C

#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);

    if (a > b) printf(">");
    else if (a < b) printf("<");
    else printf("==");

    return 0;
}

C++

#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;
}

Python

import sys
input = sys.stdin.readline

a, b = map(int, input().rstrip().split())
print('>' if a > b else ('<' if a < b else '=='))

Java

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a > b) System.out.println(">");
        else if (a < b) System.out.println("<");
        else System.out.println("==");
    }
}
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/10   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함