Search

반복문3_개념04_배수_누적

대분류
STEP03 조건문/일차반복문
문제 난이도
필수
소분류
일차반복문3_개념

영상

개념

<script> /* [문제] 40~100 사이에 5의 배수만 출력한다. 반복문 종료 후 5의 배수의 전체 합을 출력하시오. [정답] 40 45 50 55 60 65 70 75 80 85 90 95 100 합 = 910 */ let total = 0; let i = 40; while(i <= 100) { if(i % 5 == 0) { console.log(i); document.write(i + "&nbsp"); total += i; } i += 1; } console.log("total = " + total); document.write("<br>"); document.write("합 = " + total); </script>
Java
복사