-
[백준 문제풀이 C언어] 2588번 곱셈백준 문제풀이 2023. 9. 30. 23:00반응형
이 문제는 나머지를 구하는 %를 잘 사용하면 쉽게 풀 수 있다.
먼저 (3)을 구하기 위해서는 (2)의 일의 자리가 필요하다는 것을 알 수 있다.
여기서 일의 자리를 구하기 위해 (2)%10을 하게 되면 나머지가 일의자리 숫자가 된다.
ex) 271%10 = 1 (나머지 연산자 %)
그러면 (1) X((2)%10) 이 (3)이라는 것을 알 수 있다.
똑같이 (4)을 구하면 되는데 (4) 번은 십의자리 숫자가 필요하므로 (2)%100을 하면 된다.
하지만 이렇게 되면 나머지가 두 자릿수가 나오므로 나머지를 나눌필요가 있다.
따라서 ((2)%100)/10을 하면 (2)의 십의 자리 숫자만 구할 수 있다.
ex)(271%100)/10 = 7 (나머지 연산자 %)
마지막으로 (5)은 나머지가 아닌 몫이 필요하므로 (2)/100을 하면 된다.
ex) 271/100 = 2
※계산식을 쓸 때 소괄호 주의!
728x90반응형'백준 문제풀이' 카테고리의 다른 글
[백준 문제풀이 C언어] 10171번 고양이 (0) 2023.10.01 [백준 문제풀이 C언어] 11382번 꼬마 정민 (0) 2023.09.30 [백준 문제풀이 C언어] 10430번 나머지 (0) 2023.09.28 [백준 문제풀이 C언어] 18108번 1988년생인 내가 태국에서는 2541년생? (0) 2023.09.27 [백준 문제풀이 C언어] 10926번 ??! (0) 2023.09.27