求VB用 for循环 编写的一个小程序
用for循环,编程求1,2,3,4……100以及3,6,9,……99之和。
简短就好了,谢谢
谢谢你,可是我还是不会阿。这是一道考试的复习卷,我要答案呀。。可以麻烦热心人再帮帮我吗?
求1,2,3,4……100的和
Private Sub Form_Load()
Form1.AutoRedraw = True
Dim a As Integer, i As Integer
a = 0
For i = 1 To 100
a = a + i
Next i
Print a
End Sub
求3,6,9,……简备谈敬99的拦侍毁和
Private Sub Form_Load()
Form1.AutoRedraw = True
Dim a As Integer, i As Integer
a = 0
For i = 3 To 99 Step 3
a = a + i
Next i
Print a
End Sub
没学过VB,不散闷过可以写出袜掘歼for循环
int sum;
for(int i=1;i<=100;i++){
sum+=i;
}
第二告冲个
int sum;
for(int i=3;i<100;i+3){
sum+=i;
}
求1,2,3,4...100 之和
Dim sum As Integer
For i = 1 To 100
sum = sum + i
Next
求3,伏祥6,旅档9,拆厅乱……99之和
Dim sum As Integer
For i = 3 To 99
sum = sum + i
i = i + 1
Next
变量 sum 为值。
Private Sub Command1_Click()
Dim x, y As Long
y = 0
For x = 1 To 100
y = y + x
Next x
MsgBox y
End Sub
Private Sub Command2_Click()
Dim x, y As Long
y = 0
For x = 3 To 99 Step 3
y = y + x
Next x
MsgBox y
End Sub