Search

반복문3_개념05_약수_누적

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

영상

개념

<script> /* [문제] 18의 약수를 출력하고, 전체 합을 구하시오. [정답] 1 2 3 6 9 18 합 = 39 */ let num = 18; let total = 0; let i = 1; while(i <= num) { if(num % i == 0) { document.write(i + "&nbsp;"); total += i; } i += 1; } document.write("<br>"); document.write("합 = " + total); </script>
Java
복사