vb第四章选择结构和循环结构编程题Word格式.docx

上传人:b****6 文档编号:20741104 上传时间:2023-01-25 格式:DOCX 页数:15 大小:17.52KB
下载 相关 举报
vb第四章选择结构和循环结构编程题Word格式.docx_第1页
第1页 / 共15页
vb第四章选择结构和循环结构编程题Word格式.docx_第2页
第2页 / 共15页
vb第四章选择结构和循环结构编程题Word格式.docx_第3页
第3页 / 共15页
vb第四章选择结构和循环结构编程题Word格式.docx_第4页
第4页 / 共15页
vb第四章选择结构和循环结构编程题Word格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

vb第四章选择结构和循环结构编程题Word格式.docx

《vb第四章选择结构和循环结构编程题Word格式.docx》由会员分享,可在线阅读,更多相关《vb第四章选择结构和循环结构编程题Word格式.docx(15页珍藏版)》请在冰豆网上搜索。

vb第四章选择结构和循环结构编程题Word格式.docx

EndIf

p=mModn

DoWhilep<

>

o

m=n

n=p

p=mModn

Loop

Text3.Text=n

2.1最小公倍数

DimmAsInteger,nAsInteger,pAsInteger,tAsInteger

t=m*n

MsgBox"

数据错误!

End

Ifm=0Orn=0Then

Text3.Text=0

Else

Do

Ifp=0Then

ExitDo

m=n

n=p

LoopUntilFalse

Text3.Text=t/n

3.九九乘法表

DimIAsInteger,JAsInteger,MAsInteger,sAsString

ForI=1To9

s="

ForJ=1ToI

M=I*J

s=s&

J&

"

*"

&

I&

="

M&

NextJ

List1.AddItems

NextI

4.求ABCD—CDC=ABC题

Fora=1To9:

Forb=0To9

Forc=1To9:

Ford=0To9

x=a*1000+b*100+10*c+d

y=c*100+d*10+c

z=a*100+b*10+c

Ifx-y=zThen

Printx;

y;

z

Next

5.求前100项和,平均数题

PrivateSubForm_click()

n=1:

s=0

DoWhilen<

=100

s=s+n

n=n+1

Prints,n-1,s/(n-1),s*(n-1)

6.输入10个数找出正数,负数,零的个数

Dimi,t,x1,x2,x3AsInteger

Fori=1To10

t=Val(InputBox("

请输入第"

i&

个数:

显示"

Ift>

x1=x1+1

ElseIft<

x2=x2+1

Else

x3=x3+1

EndIf

Next

Print"

正数的个数:

x1

负数的个数:

x2

零的个数:

x3

7.Fibonacci数列(用数组做)

Fori=1To30

List1.AddItemFib(i)

PrivateFunctionFib(n)

Ifn<

3Then

Fib=1

Fib=Fib(n-1)+Fib(n-2)

EndFunction

PrivateSubList1_Click()

List1.AddItem=Fib

8.输入十个数打印并找出最大数,最小数

Dima(9),i,max,minAsInteger

Fori=0To9

a(i)=Val(InputBox("

i+1&

))

Printa(i);

max=a(0)

Ifa(i)>

maxThenmax=a(i)

Ifa(i)<

minThenmin=a(i)

Print

最大数为:

max;

最小数为:

min

9.100元换成40张等值的10,5,2,1的钱的题

Forx=1To10

Fory=1To20

Forz=1To50

w=40-x-y-z

If10*x+5*y+2*z+w=100Andx*y*z*w>

h=Format(x,"

@@@@"

)&

Format(y,"

@@@@@"

)_

&

Format(z,"

Format(w,"

List1.AddItemh

Nextz

Nexty

Nextx

10.找出三位数的回文数并打印,并求其个数

DimnAsInteger

Forn=101To999

a=Int(n/100)

b=Int((n-a*100)/10)

c=n-a*100-b*10

Ifa=cThenList1.AddItemn

PrintList1.ListCount

10-2回文字判断

1)按定义判断

先求出字符串的反序字符串,然后和原字符串比较,如果相等则是回文,否则不是回文。

DimstrAsString,iAsInteger

'

以下求Text1中文本的反序串str

Fori=1ToLen(Text1)

str=Mid(Text1,i,1)&

str

Nexti

Ifstr=Text1ThenMsgBox"

是回文"

ElseMsgBox"

不是回文"

(2)首尾字符的成对比较

将字符串折半比较,若每对字符都相等则是回文,否则只要有一对字符不等就不是回文。

DimiAsInteger

Fori=1ToLen(Text1)\2

IfMid(Text1,i,1)<

Mid(Text1,Len(Text1)-i+1,1)ThenExitFor

Ifi>

Len(Text1)\2ThenMsgBox"

11.求1-10之间阶乘题

DimiAsInteger,sAsDouble

i=1

DoWhilei<

=10

s=1

Forj=1Toi

s=s*j

Nextj

Printi;

!

;

s

i=i+1

Loop

12.水仙花题

DimiAsInteger,mAsInteger

Fori=100To999

m=(iMod10)^3+_

(i\10Mod10)^3+(i\100)^3

Ifm=iThenPrinti

Nexti

PrivateSubCommand2_Click()

Forb=0To9:

Forc=0To9

x=a*100+b*10+c

Ifx=a^3+b^3+c^3Then

Printx

13.打印菱形

Fori=1To5

PrintSpc(6-i);

PrintSpc

(1);

Fori=5To1Step-1

14.用Do循环设计例4.11中的s=1×

…×

n的值,其中n由输入对话框获得。

n=InputBox("

请输入n的值:

Do

Val(n)ThenExitDo

s=s*i

s="

+Str(s),0,"

计算结果"

15.求由数字0、1、2、3、4组成的所有无重复数字的3位正整数。

DimaAsInteger,bAsInteger,cAsInteger,nAsInteger

Fora=1To4

Forb=0To4

Forc=0To4

Ifa<

bAndb<

cAnda<

cThen

Printa*100+b*10+c;

或为List1.AddItema*100+b*10+c

n=n+1

IfnMod5=0ThenPrint

Nextc

Nextb

Nexta

课后题

1.

请输入一个数"

Ifx>

0Thenx=MsgBox("

是正数"

48,显示)

Ifx=0Thenx=MsgBox("

是零"

Ifx<

是负数"

64,显示)

2.

DimaAsSingle

DimbAsSingle

DimcAsSingle

DimtAsSingle

a=Val(InputBox("

请输入第一个数"

从大到小排序"

b=Val(InputBox("

请输入第二个数"

c=Val(InputBox("

请输入第三个数"

Ifa<

bThent=a:

a=b:

b=t

cThent=a:

a=c:

c=t

Ifb<

cThent=b:

b=c:

Print"

从大到小的顺序为:

a;

b;

c

3.

StaticnAsInteger

x=Text1.Text

Ifx="

123"

Then

欢迎进入本系统"

输入错误"

n=n+1

Ifn=3ThenEnd

Text1.Text="

4.

IfLeft(Text1.Text,2)=1Then

Text2.Text="

一年级"

IfLeft(Text1.Text,2)=2Then

Text2.Text="

二年级"

IfLeft(Text1.Text,2)=3Then

三年级"

IfLeft(Text1.Text,2)=4Then

四年级"

IfMid(Text1.Text,5,1)=2Then

Text3.Text="

博士生"

IfMid(Text1.Text,5,1)=3Then

硕士生"

IfMid(Text1.Text,5,1)=4Then

本科生"

IfMid(Text1.Text,5,1)=5Then

专科生"

5.

DimxAsInteger

Forx=100To200

IfxMod3=0OrxMod5=0Then

List1.AddItemx

PrintList1.ListCount

6.

a=1:

b=1

List1.AddItema

List1.AddItemb

Forn=1To28

c=a+b

a=b

b=c

List1.AddItemc

7.完备数

Dimm,i,j,s

j="

结果:

Form=2To1000

Fori=1Tom-1

IfmModi=0Thens=s+i

Ifs=mThenj=j&

m&

"

Printj

DimmAsInteger,sAsInteger

Form=2To1000

s=0

Fori=1Tom-1

IfmModi=0Thens=s+i

Ifs=mThenPrintm

8.

Timer1.Enabled=True

Timer1.Interval=1000

PrivateSubTimer1_Timer()

Text1.Text=Val(Text1.Text)-1

IfText1.Text=0Then

y=MsgBox("

预定时间到了"

64,"

倒计时"

9.

PrivateSubOption1_Click()

r=Val(Text1.Text)

s=3.*r^2

圆的面积为:

PrivateSubOption2_Click()

r=Val(Text1.Text)

c=2*3.*r

圆的周长为:

10.

PrivateSubCombo1_KeyPress(KeyAsciiAsInteger)

IfKeyAscii=13Then

Fork=0ToCombo1.ListCount-1

IfCombo1.Text=Combo1.List(k)Then

输入项已存在组合框中"

ExitSub

Nextk

Combo1.AddItemCombo1.Text

已添加输入项"

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 自我管理与提升

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1