영상
개념
<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 + " ");
total += i;
}
i += 1;
}
document.write("<br>");
document.write("합 = " + total);
</script>
Java
복사