문제 링크: https://www.acmicpc.net/problem/1008
백준 입출력과 사칙연산 5단계 - 1008번 A/B를 풀어보았다.
풀이: 정수 두 개를 입력받고, 나눈 값을 출력한다.
C++의 경우, 실제 정답과 출력값의 절대오차 또는 상대오차가 10-9 이하라는 조건을 맞추기 위해선 cout.precision()을 써야 하기에, 입력값을 실수형으로 받는다.
C++
#include <iostream>
using namespace std;
int main() {
double first, second;
cin >> first >> second;
cout.precision(10);
cout << first/second;
}
Python
a,b=map(int,input().split())
print(a/b)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double a = sc.nextInt();
double b = sc.nextInt();
System.out.printf("%.9f",a/b);
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
??! 풀이 (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 |