Swimmer

[백준] A/B, 1008, C 본문

코딩 문제

[백준] A/B, 1008, C

Zach Choi 2022. 11. 22. 23:45
  • 포인트
    • 부동 소수점에 대해 이해하고 있나?
    • float32_t (4byte), float64_t (8byte)의 연산 결과 차이를 알고 있나?
#include <stdio.h>

// 포인트 
// 8byte 자료형을 사용하면 10-9 자릿수까지 정확하게 표현가능
// 4byte 자료형 사용 시, 10-8 자릿수부터 연산 결과 이상해짐
// 4byte -> 32bit, 1bit 는 부호, 8bit 는 지수(소숫점), 23bit는 가수
// 이 방식은 IEEE에서 표준으로 제안한 방식 (IEEE 754 Standard for Floating-Point Arithmetic)


typedef long int int64_t;
typedef double float64_t;

typedef int int32_t;
typedef float float32_t;

int main()
{
	int64_t s64_1stVal = 0, s64_2ndVal = 0;
	float64_t f64_1stVal = 0.0f, f64_2ndVal = 0.0f;
	float64_t f64_RetVal = 0.0f;

	while (1)
	{
		scanf_s("%d", &s64_1stVal);
		scanf_s("%d", &s64_2ndVal);

		f64_1stVal = (float64_t)s64_1stVal;
		f64_2ndVal = (float64_t)s64_2ndVal;

		printf_s("%f \n", f64_1stVal);
		printf_s("%f \n", f64_2ndVal);

		f64_RetVal = f64_1stVal / f64_2ndVal;

		printf_s("%.10f \n", f64_RetVal);
	}
}

'코딩 문제' 카테고리의 다른 글

[백준] 유기농 배추, 1012, C  (0) 2022.11.28
[백준] 다리놓기, 1010, C  (0) 2022.11.25
[백준] 행렬 덧셈, 2738, C  (0) 2022.11.21
[백준] 알람 시계, 2884, C/C++  (0) 2022.11.20
[백준] 곱셈, 2588, C/C++  (0) 2022.11.19
Comments