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

2024-11-17 22:25:57
推荐回答(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