1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>while 문</title></head>
<body>
<h3>while 문으로 0에서 n까지 합</h3>
<hr>
<script>
var n = prompt("0보다 큰 정수를 입력하세요"0);
= parseInt(n); // 문자열을 숫자로 바꿈
 
var i=0, sum=0;
while(i<=n) { // i가 0에서 n까지 반복
    sum += i;
    i++;
}
document.write("0에서 " + n + "까지 합은 " + sum);
</script>
</body>
</html>
 
cs





Posted by 너래쟁이
: