欢迎来到天天文库
浏览记录
ID:16958392
大小:93.50 KB
页数:13页
时间:2018-08-26
《vb 常考编程题型》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.利用随机函数产生20个50到100之间的随机整数,显示它们的最大值、最小值和平均值DimmaxAsInteger,minAsInteger,sumAsIntegern=Int(Rnd*51)+50max=nmin=nsum=sum+nPrintn;Fori=1To19Randomizen=Int(Rnd*50)+50Ifn>maxThenmax=nIfn2、辗转相除法Dimm%,n%,r%,t5m=InputBox("请输入第一个整数")n=InputBox("请输入第二个整数")Ifm3、公约是"&iExitForEndIfNextiPrintn&","&m&"这两个数的最小公倍数是"&n*m/iEndSub3判断一个数是否为素数,假定概数是n方法一:如果是不素数提前结束循环,是素数,退出循环是循环变量的值不满足终止20currencydeposit,weprescribeapassonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebo4、ndsapplyformortgageloans,acceptingonlythelenderPrivateSubForm_Click()Dimn%,i%n=InputBox("请输入一个数")Fori=2Ton-1IfnModi=0ThenPrintn&"不是素数"ExitForEndIfNextiIfi=nThenPrintn&"是素数"EndIfEndSub方法二:不管这个数是否为素数,假定它是素数,用一个变量(一般用flag)记住它是素数的状态(flag=1),否则反之flag=0PrivateSubForm_Click()Dimn%,i%,flag%flag=1n=5、InputBox("请输入一个数")Fori=2Ton-1IfnModi=0Thenflag=0ExitForEndIfNextiIfflag=1ThenPrintn&"是素数"ElsePrintn&"不是素数"EndIfEndSub4找出100到300之间的所有素数,并且5个一行输出PrivateSubForm_Click()Dimn%,i%,flag%n=0Forj=100To300flag=1Fori=2Toj-1IfjModi=0Thenflag=0ExitForEndIfNextiIfflag=1Then20currencydeposit,weprescribeap6、assonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebondsapplyformortgageloans,acceptingonlythelenderPrintj;n=n+1IfnMod5=0ThenPrintEndIfNextjEndSub5求DimiAsInteger,fzAsInteger,fmAsIntegerDimsumAsSingleD7、imtAsSinglefz=1t=1i=1sum=0DoWhile1/t>=0.000001sum=sum+fz/ti=i+1t=t*(2*i)*(2*i+1)fz=-fzLoopForm1.Print"其和为",Format(sum,"0.0000000")6求1+3+5+7+……+100的和PrivateSubForm_Click()Dimi%,sum%sum=0Fori=1To100Step2sum=sum+iNextiPrint"1+3+....+100="&sumEndSub7求1!+2!+3
2、辗转相除法Dimm%,n%,r%,t5m=InputBox("请输入第一个整数")n=InputBox("请输入第二个整数")Ifm3、公约是"&iExitForEndIfNextiPrintn&","&m&"这两个数的最小公倍数是"&n*m/iEndSub3判断一个数是否为素数,假定概数是n方法一:如果是不素数提前结束循环,是素数,退出循环是循环变量的值不满足终止20currencydeposit,weprescribeapassonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebo4、ndsapplyformortgageloans,acceptingonlythelenderPrivateSubForm_Click()Dimn%,i%n=InputBox("请输入一个数")Fori=2Ton-1IfnModi=0ThenPrintn&"不是素数"ExitForEndIfNextiIfi=nThenPrintn&"是素数"EndIfEndSub方法二:不管这个数是否为素数,假定它是素数,用一个变量(一般用flag)记住它是素数的状态(flag=1),否则反之flag=0PrivateSubForm_Click()Dimn%,i%,flag%flag=1n=5、InputBox("请输入一个数")Fori=2Ton-1IfnModi=0Thenflag=0ExitForEndIfNextiIfflag=1ThenPrintn&"是素数"ElsePrintn&"不是素数"EndIfEndSub4找出100到300之间的所有素数,并且5个一行输出PrivateSubForm_Click()Dimn%,i%,flag%n=0Forj=100To300flag=1Fori=2Toj-1IfjModi=0Thenflag=0ExitForEndIfNextiIfflag=1Then20currencydeposit,weprescribeap6、assonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebondsapplyformortgageloans,acceptingonlythelenderPrintj;n=n+1IfnMod5=0ThenPrintEndIfNextjEndSub5求DimiAsInteger,fzAsInteger,fmAsIntegerDimsumAsSingleD7、imtAsSinglefz=1t=1i=1sum=0DoWhile1/t>=0.000001sum=sum+fz/ti=i+1t=t*(2*i)*(2*i+1)fz=-fzLoopForm1.Print"其和为",Format(sum,"0.0000000")6求1+3+5+7+……+100的和PrivateSubForm_Click()Dimi%,sum%sum=0Fori=1To100Step2sum=sum+iNextiPrint"1+3+....+100="&sumEndSub7求1!+2!+3
3、公约是"&iExitForEndIfNextiPrintn&","&m&"这两个数的最小公倍数是"&n*m/iEndSub3判断一个数是否为素数,假定概数是n方法一:如果是不素数提前结束循环,是素数,退出循环是循环变量的值不满足终止20currencydeposit,weprescribeapassonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebo
4、ndsapplyformortgageloans,acceptingonlythelenderPrivateSubForm_Click()Dimn%,i%n=InputBox("请输入一个数")Fori=2Ton-1IfnModi=0ThenPrintn&"不是素数"ExitForEndIfNextiIfi=nThenPrintn&"是素数"EndIfEndSub方法二:不管这个数是否为素数,假定它是素数,用一个变量(一般用flag)记住它是素数的状态(flag=1),否则反之flag=0PrivateSubForm_Click()Dimn%,i%,flag%flag=1n=
5、InputBox("请输入一个数")Fori=2Ton-1IfnModi=0Thenflag=0ExitForEndIfNextiIfflag=1ThenPrintn&"是素数"ElsePrintn&"不是素数"EndIfEndSub4找出100到300之间的所有素数,并且5个一行输出PrivateSubForm_Click()Dimn%,i%,flag%n=0Forj=100To300flag=1Fori=2Toj-1IfjModi=0Thenflag=0ExitForEndIfNextiIfflag=1Then20currencydeposit,weprescribeap
6、assonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebondsapplyformortgageloans,acceptingonlythelenderPrintj;n=n+1IfnMod5=0ThenPrintEndIfNextjEndSub5求DimiAsInteger,fzAsInteger,fmAsIntegerDimsumAsSingleD
7、imtAsSinglefz=1t=1i=1sum=0DoWhile1/t>=0.000001sum=sum+fz/ti=i+1t=t*(2*i)*(2*i+1)fz=-fzLoopForm1.Print"其和为",Format(sum,"0.0000000")6求1+3+5+7+……+100的和PrivateSubForm_Click()Dimi%,sum%sum=0Fori=1To100Step2sum=sum+iNextiPrint"1+3+....+100="&sumEndSub7求1!+2!+3
此文档下载收益归作者所有