Search

반복문3_문제07_배수_누적_홀수

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

영상

문제

<script> /* [문제] 100 ~ 300 사이의 숫자 중에서 [조건1] 9의 배수이면서 홀수인 수를 출력하고, [조건2] 그 총합을 구하시오. [조건3] 위 수의 개수를 구하시오. [정답] 117 135 153 171 189 207 225 243 261 279 297 total = 2277 count = 11 */ </script>
Java
복사

해설

<script> /* [문제] 100 ~ 300 사이의 숫자 중에서 [조건1] 9의 배수이면서 홀수인 수를 출력하고, [조건2] 그 총합을 구하시오. [조건3] 위 수의 개수를 구하시오. [정답] 117 135 153 171 189 207 225 243 261 279 297 total = 2277 count = 11 */ let total = 0; let count = 0; let i = 100; while(i <= 300) { if(i % 9 == 0 && i % 2 != 0) { 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
복사