-
백준 1008번 : A/B [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 28. 20:52
https://st-lab.tistory.com/212
해당 블로그가 설명이 잘 되어있어 참고했다.
컴퓨터는 비트로 수를 표현한다.
음수는 2의보수로 표현가능함을 전공 기초를 통해 이미 배웠다.
그러나 소수는 과연 어떻게 표시야 하는지?
1/3은 0.33333......... 무한한 소수이다.
정확하게는 표현할 수 없다.
결국 근사치를 표현하는것이 최선이며
정확한 값에 조금이라도 더 근접하기 위해서는 최대한 많은 비트를 쓸 수 있는 자료형을 써야 한다.
실수형 자료형은 두 가지가 있다
float : 4bytes : 32bits
double : 8bytes : 64bits
long double : 16bytes : 128bits
* 다만 long double은 gcc, g++ 환경에서 컴파일시 16bytes이고 vs에서는 8bytes까지 나온다.
[C]
[C++]
C++의 경우 출력에 있어 두 가지 지식이 필요하다고 한다.
1. std::fixed _ 소수점을 고정시킴
2. std::cout.precision(n) _ n자리까지 표현
소수점 표현에 대한 예제
'소프트웨어전공 > 알고리즘 문제풀이' 카테고리의 다른 글
프로그래머스 완주하지못한선수 [C++] feat.다양한 풀이방법 (0) 2021.10.06 프로그래머스 폰켓몬 _ [C++] (0) 2021.09.28 C++ 숫자의 총 개수 (0) 2021.09.26 백준 1152번 단어의 개수 _ [C++] (0) 2021.09.25 백준 1110번 더하기 사이클 [C++] (0) 2021.09.24