-- 예전 기록/BOJ

[ BOJ ] 10869 : 사칙연산 ( BRONZE 5 ) / C, C++, Python, Java

rejo 2023. 6. 20. 15:02

문제

두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오. 

입력

두 자연수 A와 B가 주어진다. (1 ≤ A, B ≤ 10,000)

출력

첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A*B, 넷째 줄에 A/B, 다섯째 줄에 A%B를 출력한다.

풀이 과정

기존에 A+B, A-B, AxB, A/B 문제를 풀었던 것처럼 풀이하면 된다.

C

#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    printf("%d\n", a+b);
    printf("%d\n", a-b);
    printf("%d\n", a*b);
    printf("%d\n", a/b);
    printf("%d", a%b);
    return 0;
}

C++

#include <iostream>
using namespace std;

int main(void) {
    int a, b; cin >> a >> b;
    cout << a+b << endl << a-b << endl << a*b << endl << a/b << endl << a%b;
    return 0;
}

Python

a, b = map(int, input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b)
print(a%b)

Java

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.println(a+b);
        System.out.println(a-b);
        System.out.println(a*b);
        System.out.println(a/b);
        System.out.println(a%b);
    }
}