Search

반복문3_문제08_배수_누적_백의자리

대분류
STEP03 조건문/일차반복문
문제 난이도
LV02
소분류
일차반복문3_문제

영상

문제

<script> /* [문제] 1000~2000 사이의 숫자 중에서 [1] 16의 배수 중에서 백의 자리가 7인 수만 출력하고, [2] 그 합을 구하시오. [3] 개수를 구하시오. [정답] 1712 1728 1744 1760 1776 1792 total = 10512 count = 6 */ </script>
Java
복사

해설

<script> /* [문제] 1000~2000 사이의 숫자 중에서 [1] 16의 배수 중에서 백의 자리가 7인 수만 출력하고, [2] 그 합을 구하시오. [3] 개수를 구하시오. [정답] 1712 1728 1744 1760 1776 1792 total = 10512 count = 6 */ let total = 0; let count = 0; let i = 1000; while(i <= 2000) { let unit = parseInt(i % 1000 / 100); if(i % 16 == 0 && unit == 7) { console.log(i); document.write(i + "&nbsp;"); total += i; count += 1; } i += 1; } console.log("total = " + total); console.log("count = " + count); document.write("<br>"); document.write("total = " + total + "<br>"); document.write("count = " + count); </script>
Java
복사