bshy.net
当前位置:首页>>关于求VB编程,两个按钮"奇数和","偶数和".输入整数n...的资料>>

求VB编程,两个按钮"奇数和","偶数和".输入整数n...

Private Sub Command1_Click() Dim n As Integer Dim s As Double s = 0 n = Val(Text1.Text) For i = 1 To n If i Mod 2 = 1 Then s = s + i Next i Text3.Text = sEnd SubPrivate Sub Command2_Click() Dim n As Integer Dim s As Double s = ...

代码及注释如下: Private sub command1_click() for i=1 to n'i从1到n循环 if i mod 2=0 then'利用mod函数来判断i的值是偶数还是奇数 oushuhe=oushuhe+i'如果是偶数,就将其累加到oushuhe变量中 else jishuhe=jishuhe+i'如果是奇数,就将其累加...

Private Sub Form_Click()Dim s As Integer, b As Integer, i As Integer, ji As Long, opu As Longa = InputBox("输入一个自然数")b = InputBox("输入另一个自然数")If b > a Then For i = a To b If i Mod 2 = 1 Then ji = ji + i Print i; E...

你应该是想达到这个效果吧,如上图。逐行手敲,亲测可用。有问题可以问我。Private Sub Command1_Click()Dim a, bText3.Text = Val(Text1.Text) + Val(Text2.Text)Text4.Text = Val(Text1.Text) * Val(Text2.Text)If Val(Text1.Text) Mod 10 = ...

Private Sub Command1_Click() Dim n As Long n = Val(Text1.Text) If n Mod 2 = 0 Then Label2.Caption = "是偶数" Else Label2.Caption = "是奇数" End If End Sub 希望采纳

dim i as integer dim js as integer,os as integer,x as integer js=0 os=0 for i=1 to 20 x=val(inputbox("请输入20个整数:","输入")) if x mod 2 = 0 then os=os+1 else js=js+1 next print js,os

Private Sub Form_Click() Dim A(1 to 10) as Long Dim Jc as long ,Oc as Long For i=1 to 10 A(I)=Val(InputBox("请输入第" & i & "个数据")) If A(i) mod 2 =0 then oc=oc+A(I) If A(i) mod 2 =1 then jc=jc+A(i) Next Print "奇数的和为:" &...

Private Sub Command1_Click() Dim a As String Dim n As Long a = InputBox("输入一个正整数", "输入") n = CLng(a) If n Mod 2 = 0 Then Print n; "是偶数" Else Print n; "是奇数" End If End Sub

Private Sub Command1_Click() Dim a As Integer, i As Integer a = 0 For i = CInt(Text1.Text) To CInt(Text2.Text) If i Mod 2 0 Then a = a + i End If Next print a End Sub

dim n as integer n=val(inputbox("请输入一个整数")) if n mod 2=0 then print 偶数 else print 奇数 end if

网站首页 | 网站地图
All rights reserved Powered by www.bshy.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com