<题目>用 Do While…Loop和Do …Loop While语句分别计算累加和:S=1+2+3+4+…+n。

2024年11月17日 22:25
有1个网友回答
网友(1):

假设n=100.
一.Do While…游毁旅余宏LOOP实现
Dim i As Integer, sum As Integer
sum = 0: i = 1
Do While i <= 100
sum = sum + i
i = i + 1
Loop

二神凳.Do…Loop While实现:
Dim i As Integer, sum As Integer
sum = 0: i = 1
Do
sum = sum + i
i = i + 1
Loop While i <= 100
Print sum