VB统计1-100范围内的偶数的个数及这些偶数之和
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/11 01:30:48
q=0:e=0Fori=1To100IfiMod2=0Thene=e+1Elseq=q+1EndIfNextPrint"奇数个数=";q,"偶数个数=";e
这个采用枚举算法:枚举的关键:一一列举,逐个检验一一列举:用循环逐个检验:用选择n3=0'存放3的倍数的个数n7=0'存放7的倍数的个数Fori=1To100ifiMod3=0Thenn3=n3+1i
语句自己找给思路.第一种:暴力运算1.申请2个变量jsum,osum分别放奇数和、偶数和.赋初值0.2.做个循环从1到100,变量用i2.1判断i是否为奇数,是的话jsum=jsum+i,否则osum
DimiasInteger,jasInteger,oasIntegerj=0o=0Fori=1To100Step2j=j+io=o+(i+1)NextDebug.print"100以内的奇数和:"&j
先在窗体上添加一个TextBox文本框(将其Multiline属性设置为True,并调整宽高以便能较好的显示出100个随机数)和一个Button按钮.然后双击Button按钮跳转到代码编辑窗口,粘帖以
PrivateSubCommand1_Click()Doa=Val(InputBox("输入整数,-1结束:"))IfaMod2=0Thens=s+1LoopUntila=-1Print"共有";s;
PrivateSubCommand1_Click()Dimi,sum1,sum2AsIntegersum1=0sum2=0Fori=1To100IfiMod2=1Thensum1=sum1+iElse
OptionExplicitPrivateSubForm_Click()Form1.AutoRedraw=TrueClsDimAAsInteger,SuAsBoolean,IAsInteger,JAs
Dimm(99)AsInteger,n(9)AsInteger,iAsInteger,kAsIntegerRandomizeFori=0To99m(i)=Int(Rnd*100)Printm(i);k
PrivateSubCommand1_Click()Fori=0ToList1.ListCount-1j=j+1Ifj=11ThenExitForIfList1.List(i)NextEndSubPr
PrivateSubForm_Click()DimiAsIntegerDimjAsIntegerDimsAsIntegers=0Fori=10To30IfiMod2=0ThenPrinti;EndIf
在窗口上建立一个按钮:FunctionTotal(Num1,Num2)AsString'Num1为奇数和'Num2为偶数和Fori=1To100IfiMod20ThenNum1=Num1+iElseN
PrivateSubCommand1_Click()Fori=1To100IfiMod7=0Thenn=n+1EndIfNextiPrintnEndSu
PrivateSubCommand1_Click()Dims&,i&i=2WhileiMod115OriMod173‘先找到符合条件的第一个ii=i+2WendFori=iTo5000Step374’
添加两个控件名字分别为sc、tj的按钮.'定义一个窗体数组变量dima(10)asinteger'生成是个随机数privatesubsc_click()'下面这一句可以得到不同的随机数randomiz
PrivateSubCommand1_Click()c=InputBox("","","")Fora=1To100b=Int(Rnd*99)IfInt(Right(Str(b),1))=Int(c)T
Dimi,sAsIntegerFori=2To100step2s=s+iNexti
PrivateSubCommand1_Click()Dimi%,j3%,j7%Fori=1To100IfiMod3=0Thenj3=j3+1IfiMod7=0Thenj7=j7+1NextPrint"
窗体上放个CommandButton和两个Label:PrivateSubCommand1_Click()DimiAsInteger,jAsInteger,nAsIntegerLabel1.Capti
PrivateSubForm_Click()Dima(30)AsIntegerDimiAsIntegerRandomizeFori=1To30a(i)=Int(100*Rnd)NextiFori=1T