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


 

Posted by 너래쟁이
: