문제 링크: https://www.acmicpc.net/problem/10869
백준 입출력과 사칙연산 6단계 - 10869번 사칙연산을 풀어보았다.
풀이: 자연수 두 개를 입력받아 연산값을 출력하면 된다. A/B의 경우 몫만 구하면 되기 때문에 따로 처리할 필요가 없다.
C++
#include <iostream>
using namespace std;
int main() {
int first, second;
cin >> first >> second;
cout << first+second<<'\n';
cout << first-second<<'\n';
cout << first*second<<'\n';
cout << first/second<<'\n';
cout << first%second;
}
Python
a,b=map(int,input().split())
print(a+b)
print(a-b)
print(a*b)
print(int(a/b)) # 몫 구하기
print(a%b)
Java
import java.util.Scanner;
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);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
1998년생인 내가 태국에서는 2541년생?! 풀이 (0) | 2022.12.30 |
---|---|
??! 풀이 (0) | 2022.12.30 |
A/B 풀이 (0) | 2022.12.30 |
A×B 풀이 (0) | 2022.12.30 |
A-B 풀이 (0) | 2022.12.30 |