利用VB循环语句计算和输出1-100的和
For i = 1 To 100 Sum = Sum + i Next Print "0~100的和为: "; Sum End Sub
用VB的循环语句求1到100的奇数和与偶数积
Private Sub Form_Click()Dim i As Integer, sum As Integer, aa As Double aa = 1 For i = 1 To 100 If i Mod 2 = 0 Then aa = aa * i Else sum = sum + i End If Next i Debug.Print aa, sum End Sub
用VB编写:循环语句的应用,计算1~100的偶数和?
用VB编写:循环语句的应用,计算1~100的偶数和,最简单的方法是采用计数循环来实现。dim i as integer,s as integer s=0 for i = 2 to 100 step 2 s = s + i next i print "Sum ="; s
利用循环语句 用VB计算1到100的奇数的和
Private Sub Command1_Click() Dim i As Integer Dim s As Integer For i = 1 To 100 If i Mod 2 <> 0 Then s = s + i End If Next MsgBox sEnd Sub
利用Do…Loop循环语句求从1到100的累加和
dim he as long,n as long he=0 n=1 do he=he+n n=n+1 loop untill n>100 msgbox "累加和是:" & he ‘以上是VB的写法。
VB分别用各种循环语句编写求1+2+3+……….100的和。
Private Sub Command1_Click()i = 1 Do While i <= 100 s = s + i i = i + 1 Loop Print s s = 0 For i = 1 To 100 s = s + i Next i Print s i = 1 s = 0 Do Until i > 100 s = s + i i = i + 1 Loop Print s End Sub ...
vb编程输出1-100的所有素数,并计算这样的素数合计多少个,下面我写的...
'Mod是取余数,如果说由i来取余数不可能出现1 '你可以这样: If i Mod 2 = 0 Then '它出现0的可能有50次 Private Sub Command3_Click()For i = 1 To 100 If i Mod 2 = 0 Then Sum = Sum + 1 End If Next i Me.Caption = Sum End Sub ...
vb中如何用For ··· Next ···语句求奇数和、偶数的和
求奇数和 for i=1 to 100 step 2 ss=ss+i next 求偶数和 for i=0 to 100 step 2 ss=ss+i next exit for 表示退出FOR的循环 例如在求奇数和的时候,假如当和大于100时,退出循环 for i=1 to 100 step 2 ss=ss+i if ss>=100 then exit for next ...
...each语句实现1-100的累加,且将大于1000的和值与其对应的累加值输出...
for each 只能用来遍历数组吧,要实现你的功能,应该要先定义一个1-100的数组,直接用for不更简单。int sum = 0;for(int i =1;i<=100;i++){ sum += i ;if(sum >= 1000){ System.out.println("和= " + sum+",当前值= "+i);} } ...
使用VBscript循环语句编写1到100的累加和的程序,并在浏览器中显示结果...
dim i,sum sum=0 for i=1 to 100 sum=sum+i next document.write cstr(sum)