영상
문제
<script>
/*
[문제]
[조건1] 30의 약수를 출력하고
[조건2] 전체 합을 구하시오.
[조건3] 개수를 구하시오.
[정답]
1 2 3 5 6 10 15 30
total = 72
count = 8
*/
</script>
Java
복사
해설
<script>
/*
[문제]
[조건1] 30의 약수를 출력하고
[조건2] 전체 합을 구하시오.
[조건3] 개수를 구하시오.
[정답]
1 2 3 5 6 10 15 30
total = 72
count = 8
*/
let num = 30;
let total = 0;
let count = 0;
let i = 1;
while(i <= num) {
if(num % i == 0) {
console.log(i);
document.write(i + " ");
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
복사