h Fornl 求累加和1+2+3+.+100(如) 今有100个数:1、2、 设计步骤如下: 00,试计算其累加和。 窗体界面的设计参见前面章节, 计算GN 这里仅给出命令按钮的 Click事件代 1+2+3+…+100=5050 码 Private Sub Commandl click 求累加和 Dim s as Integer, n As Integer Private Sub Commandl click s=0:n=1 Dim s As Integer, n As Integer Do While n <=100 s=0:n=1 S=Stn Do Until n>100 n=n+1 stn n=n+1 Label2 Caption=1+2+3+.+100= Loop &s Label2 Caption =1+2+3+...+100 End sub 还可以改为直到型: End sub求累加和1 + 2 + 3 +…+ 100(如)。 求累加和 设计步骤如下: 窗体界面的设计参见前面章节, 这里仅给出命令按钮的Click事件代 码: Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0: n = 1 Do While n <= 100 s = s + n n = n + 1 Loop Label2.Caption = "1+2+3+…+100 = " & s End Sub 还可以改为直到型: Private Sub Command1_Click() Dim s As Integer, n As Integer s = 0: n = 1 Do Until n > 100 s = s + n n = n + 1 Loop Label2.Caption = "1+2+3+…+100 = " & s End Sub