
몫이 아닌 전체 값을 출력해야 하기 때문에 데이터 타입에 주의해야 한다.
Bash 
bash
read a b
let a*=10**10
let r=a/b
n=0
if [ ${#r} -gt 10 ]; then
	n=${r::1}
	r=${r:1}
fi
echo $n.$r1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Bash는 연산 시 소수부를 모두 버리기 때문에 오차 범위만큼 곱한 후 계산하고 점은 직접 넣어야 한다.
let r=a/b 대신 ((r = a/b))를 사용할 수 있다. 2, 3번 라인을 ((a *= 10**10, r = a/b)) 이 한 줄로 줄일 수 있다. 백준에서는 먹히지 않는 awk, bc 명령어를 사용하면 소수부까지 출력할 수 있다.
C 
c
#include <stdio.h>
int main(void) {
	double a, b;
	scanf("%lf %lf", &a, &b);
	printf("%.9lf", a / b);
	return 0;
}1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
int, float 타입이 아닌 double을 사용해야 한다.
Node.js 
javascript
let [a, b] = require("fs").readFileSync(0).toString().trim().split(" ").map(Number);
console.log(a / b);1
2
2
PHP 
php
<?php
	fscanf(STDIN, "%d %d", $a, $b);
	echo $a / $b;
?>1
2
3
4
2
3
4
Python3 
python
a, b = map(int, input().split())
print(a/b)1
2
2
Python2와 달리 Python3은 정수끼리 나눠도 소수부까지 연산이 가능하다.
Ruby 
ruby
a, b = gets.chomp.split().map {|i| i.to_f}
puts a/b1
2
2
정수형인 to_i가 아니라 실수형인 to_f다.
Comments
Not supported comment edit and upvote
You can do it on this page if you want.