vb課后習(xí)題答案_第1頁
vb課后習(xí)題答案_第2頁
vb課后習(xí)題答案_第3頁
vb課后習(xí)題答案_第4頁
vb課后習(xí)題答案_第5頁
已閱讀5頁,還剩26頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

第八章

1、動態(tài)數(shù)組的定義

DimthisOAsString,在窗體層定義一個數(shù)組this

PrivateSubCommand1_Click()

ReDimthis(4),動態(tài)數(shù)組的定義,注意數(shù)據(jù)類型要匹配

this(2)=Hmicrosoft",不能改變維數(shù)和類型

Printthis(2)

ReDimthis(6)

this(5)="visualbasic11

Printthis(5)

EndSub

2、數(shù)組元素的輸出

DimstunameOAsString,定義一個數(shù)組stuname,類型為字符串

PrivateSubCommand2_ClickQ

ReDimstuname(4)AsString,重新定義數(shù)組,維數(shù)為4,類型為字符串

Fori=1To4

temp$=InputBoxf'entername,1),從一開始循環(huán),輸入一個名字賦一個值

stuname(i)=temp$

Print"stunamef1;i;")=";stuname(i)'在循環(huán)體中輸出/的左右加分號

Nexti1輸入四個名字

EndSub

PrivateSubForm_LoadO

FontSize=50

EndSub

3、多位數(shù)組元素的輸出

PrivateSubCommand3_ClickO

Dima(3,5)AsInteger,定義一個二維數(shù)組

Fori=1To3'控制第一維的循環(huán)變量放在最最外層循環(huán)

Forj=1To5

a(i,j)=i*),下行中I、j必須用引號,注意是二維的

Print"a(";i;a(i,j)'print放在循環(huán)體中

Nextj

Nexti

EndSub

4、數(shù)組元素的輸出

OptionBase1,下標(biāo)從1開始

PrivateSubCommand1_Click0

Dima(4,4)AsInteger

Fori=1To4

Forj=1To4

a(irj)=InputBoxCenterdata")'放在循環(huán)體中

Printa(i,j);

Nextj

Nexti

EndSub

5、數(shù)組元素的復(fù)制

OptionBase1

DimnamelO/name20,中間必須加逗號,定義空維數(shù)組,為萬能類型

PrivateSubCommand2_ClickO

,重新定義,是一維數(shù)組

ReDimname1(10)rname2(10)

Fori=1To10

msg$=lnputBox$("entername")^amelO)=lnputBox$("entername")

name1(i)=msg$,跟上述語句是一樣的效果,只是帶換了一下

Printname1(i);H,放在循環(huán)體中

Nexti

Print,換行,不能放在循環(huán)體中

Fori=1To10

name2(i)=name1(i),把數(shù)組一的值賦給數(shù)組二,必須用循環(huán)體復(fù)制

Printname2(i);"輸出

Nexti

EndSub

PrivateSubForm_LoadO

FontSize=50,不能放在窗體層

EndSub

6、輸出數(shù)組的上下界

PrivateSubCommand1_ClickO

Dima(1To10,1To100,1To1000)

PrintLBound(a,1);UBound(a,1)(Iboundandubound分別表示定義的變量的下界和上

PrintLBound(a,2);UBound(ar2)

PrintLBound(a,3);UBound(a,3)

EndSub

7、定義默認(rèn)數(shù)組

PrivateSubCommand2_Click()

Statica(5)

a(1)=100

a(2)=123.23

a(3)="zhanghaie"

a(4)="ZO"&Now

a(5)=&HAAF

Fori=1To5

Printna(";i;'*)=";a(i)

Nexti

EndSub

8、求數(shù)組的和

PrivateSubCommand3_ClickO

Dima(2),b(2),c(2),i'定義為萬能類型

a(1)=1

b⑴=1

a(2)=1

b(2)=1

Fori=0To1

c(i)=a(i)+b(i)

PrintwcC;i;?,)=??;c(i)

Nexti

EndSub

9、數(shù)組名在一個過程中不能重

PrivateSubForm_ClickO

Dima(5)

Dimb

b=8,在同一個過程中,數(shù)組名和其他變量名不能一樣

a(2)=10

Printb,a(2)

EndSub

10、erase語句的用法

StaticSubForm_ClickO

FontSize=20

Dimtest(1To20)AsInteger用static定義一k個靜態(tài)數(shù)組

Fori=1To20,循環(huán),給數(shù)組賦值并輸出

test(i)=i

Printtest(i);

Nexti

Erasetest,清空數(shù)組,還原值為0,釋放空間

Print,換行

Print"Erasetest。"輸出字符串

Print"nowthetestarrayisfilledwithzeros...”'輸出字符串

Fori=1To20

Printtest(i);輸出清空后的數(shù)組

Nexti

EndSub

11、冒泡排序法

PrivateSubCommand1_Click()

FontSize=50

Staticnumber(1To10)AsInteger

msg$="enternumberforsort"'$表示字符串,用msg$,msgtitle$只是為了代換

msgtitle$="sortdemo"

Fori%=1To10%表示為整形

number(i%)=InputBoxC'msgSfmsgtitleS")也可直接輸字符串

Nexti%

Fori%=10To2Step-1

Forj%=1Toi%-1

Ifnumber(j%)>number(j%+1)Then

t=number(j%+1)'number(j%+1),number。%)交換數(shù)值

number(j%+1)=number(|%)

number(j%)=t

EndIf

Nextj%

Nexti%

Fori%=1To10

Printnumber(i%)

Nexti%

EndSub

12統(tǒng)計人數(shù)

OptionBase1

DimscoreOAsSingle

PrivateSubForm_CIIckO

n=InputBoxC輸入學(xué)生人數(shù)n")

ReDimscore(n)

Dimcount(11)AsInteger

Fori=1Ton

score(i)=I叩utBoxC'輸入第"&i&"個學(xué)生成績")

Printscore(i);

k=lnt(score(i)/10)+1

count(k)=count(k)+1

Nexti

Print

Fori=1To10

Print(1-1)*10;"toM;(I-1)*10+9,count(i)

Nexti

Print100;Spc(9);count(11)

EndSub

PrivateSubForm_Load0

FontSize=30

EndSub

13、作業(yè)題5

OptionBase1

DimnamO,sexO,age。,culture。,addrO

PrivateSubForm_Click0

n=InputBoxf'enterpeoplenumber:11)

ReDimnam(n)

ReDimsex(n)

ReDimage(n)

ReDimculture(n)

ReDimaddr(n)

Fori=1Ton

nam(i)=InputBoxf'entername:")

Printnam(i),

sex(i)=InputBoxf'entersex:11)

Printsex(i),

age(i)=InputBoxf'Enterage:")

Printage(i),

culture6=InputBox「輸入文化程度:”)

Printculture(i),

addr(i)=InputBox("輸入籍貫:M)

Printaddr(i)

Next

100

findName=InputBoxf輸入要查詢的姓名:")

flag=0

Fori=1Ton

IffindName=nam(i)Then

Printnam(i),sex(i),age(i),culture(i),addr(i)

flag=1

EndIf

Next

Ifflag=0Then

Print”您要查詢的人不存在!!”

EndIf

msg=MsgBox。1您要繼續(xù)查找嗎?",vbYesNo+vbDefaultButtonl,"W問框")

Ifmsg=vbYesThen

GoTolOO

Else

End

EndIf

EndSub

14、作業(yè)題

PrivateSubForm_CHckO

FontSize=16

DimiAsInteger

DimjAsInteger

Dimarr(1To10,1To10)AsInteger

Fori=1To10

For]=1To10

Ifi=jOri+j=11Then

arr(i,|)=1

Else

arr(i,|)=0

EndIf

Next

Next

Fori=1To10

Forj=1To10

Printarr(i,j);

Next

Print

Next

EndSub

15、作業(yè)題8

OptionExplicit

OptionBase1

DimaOAsInteger

DimbOAsInteger

PrivateSubForm_ClickO

FontSize=26

DimiAsInteger

DimjAsInteger

DimnAsInteger,mAsInteger

n=lnputBox1請輸入矩陣的行數(shù):")

m=lnputBox("請輸入矩陣的列數(shù):")

ReDima(nrm)AsInteger

ReDimb(m,n)AsInteger

Print"轉(zhuǎn)置前的矩陣為:"

Fori=1Ton

Forj=1Tom

a(i,j)=InputBox("輸入數(shù)組A的元素值:")

Printa(i,j);

Next

Print

Next

Fori=1Ton

Forj=1Tom

b(j,i)=a(i,j)

Next

Next

Print"轉(zhuǎn)置后的矩陣為:"

Fori=1Tom

Forj=1Ton

Printb(i,|);

Next

Print

Next

EndSub

16、作業(yè)題9

PrivateSubForm_ClickO

FontSize=24

DimiAsInteger

DimjAsInteger

Dimarr(10,10)AsInteger

arr(0r0)=1

Fori=1To10

arr(i,0)=1

Forj=1Toi

Ifi=jThen

arr(i,j)=1

Else

arr(i,j)=arr(i+arr(i-1J)

EndIf

Next

Next

Fori=0To10

Forj=0Toi

PrintTab(6*j);arr(i,j);

Next

Print

Next

EndSub

17、作業(yè)題1、2

OptionExplicit

OptionBase1

Dima(1To10)AsSingle

PrivateSubCommand1_Click0

FontSize=24

DimiAsInteger

DimtAsSingle

Print"對換前的數(shù)組值依次為:"

Fori=1To10

a⑴=lnputBox("輸入數(shù)值:")

Printa(i);

Next

ForI=1To5

t=a(i)

a⑴=a(11?[)

a(11-i)=t

Next

Print

Print"對換后的數(shù)組值依次為:"

Fori=1To10

Printa(i);

Next

EndSub

PrivateSubCommand2_ClickO

DimarrAAsVariant

DimarrB

DimarrSum(8)AsVariant

DimiAsInteger

Cis

arrA=Array(2,8,7,6,4,28,70,25)

arrB=Array(79,27f32,41,57,66,78,80)

Fori=1To8

PrintarrA(i);M”;

Next

Print

Fori=1To8

PrintarrB(i);MH;

Next

Print

Fori=1To8

arrSum(i)=arrA(i)+arrB(i)

PrintarrSum(i);n

Next

EndSub

PrivateSubCommand3_Click()

FontSize=24

DimiAsInteger

DimtAsSingle

Dimb(10)AsInteger

Print"對換前的數(shù)組值依次為:"

Fori=1To10

a(i)=lnputBox("輸入數(shù)值:")

Printa(i);

Next

Fori=1To10

b(i)=a(11-i)

Next

Print

Print"對換后的數(shù)組值依次為:"

Fori=1To10

Printb(i);

Next

EndSub

18、第3題

OptionExplicit

OptionBase1

DimarrOAsInteger

DimnAsInteger

DimmAsInteger

PrivateSubCommand1_ClickO

DimiAsInteger,jAsInteger

DimmaxAsInteger

DimrowAsInteger,colAsInteger

n=lnputBox("輸入數(shù)組的行數(shù):”)

m=InputBoxC,輸入數(shù)組的列數(shù):,f)

ReDimarr(n,m)

Fori=1Ton

Forj=1Tom

arr(i,j)=l叩utBox("輸入數(shù)組的元素值:")

Printarr(i,j);

Next

Print

Next

max=arr(1,1)

row=1:col=1

Fori=1Ton

Forj=1Tom

Ifmax<arr(i,j)Then

max=arr(i,j)

row=I:col=j

EndIf

Next

Next

Print

Print"最大值的行號:row,"列號:";col

Print"最大值是:”;max

EndSub

19、第四題

OptionExplicit

OptionBase1

Dimarr(4,4)AsInteger

DimarrB(4,4)AsInteger

DimiAsInteger,jAsInteger

DimRowSum(4)AsInteger,ColSum(4)AsInteger

DimtempAsInteger

PrivateSubCommand1_ClickO

Cis

Print"輸出矩陣兩個對角線上的數(shù):"

Fori=1To4

Forj=1To4

Ifi=jThen

Printarr(i,j);

Else

Ifi+j=5ThenPrintarr(i,j);

EndIf

Next

Next

Print

EndSub

PrivateSubCommand2_ClickO

Cis

Print"分別輸出各行各列的的和:"

Fori=1To4

Forj=1To4

RowSum(i)=RowSum(i)+arr(i,j)

ColSum(j)=ColSum(j)+arr(ifj)

Next

Next

Fori=1To4

Print"第";i;"行之和為:”,RowSum(i)

Next

Print

ForI=1To4

Print"第i;"列之和為:,ColSum(i)

Next

EndSub

PrivateSubCommand3_ClickO

Cis

Print

Print"交換第一行和第三行的位置:"

Fori=1To4

Forj=1To4

arrB(i,j)=arr(i,j)

Next

Next

Forj=1To4

temp=arrB(1,j)

arrB(1,j)=arrB(3rj)

arrB(3,j)=temp

Next

Fori=1To4

Forj=1To4

PrintarrB(ir|);

Next

Print

Next

Print

EndSub

PrivateSubCommand4_Click()

Cis

Print"交換第二列和第四列的位置:"

Fori=1To4

temp=arr(i,2)

arr(i,2)=arr(i,4)

arr(ir4)=temp

Next

Fori=1To4

Forj=1To4

Printarr(i,j);

Next

Print

Next

Print

EndSub

PrivateSubForm_ClickO

Fori=1To4

Forj=1To4

arr(i,j)=l叩utBox("輸入數(shù)組的數(shù)據(jù):")

Printarr(i,j);

Next

Print

Next

Print

EndSub

20、第六題

OptionExplicit

OptionBase1

Dimnum,score,order

PrivateSubForm_ClickO

FontSize=26

DimiAsInteger

DimjAsInteger

Dimtemp,tern

num=Array(“207”,“077”,“156”,“231”,“453”,“276”,“096”,“122”,“339”,“302”)

score=Array(14.5,15.1,14.2,14.7,15.2f13.9,15.7,13.7,14.9,14.5)

Fori=1To9

Forj=1To10-i

Ifscore(|)>score(j+1)Then

temp=score(j):score(j)=score(j+1):score(j+1)=temp

tem=num(|):num(j)=num(j+1):num(j+1)=tem

EndIf

Next

Next

Print"名次運(yùn)動員號","成績"

Fori=1To10

Printi,num⑴,score(i)

Next

EndSub

21、第十題

PrivateSubForm_Click0

FontSize=20

PrintH*H

Fork=1To4

PrintTab(k*6);3*k;

Nextk

Fori=15To18

Print

Printi;

Fork=1To4

PrintTab(k*6);i*3*k;

Nextk

Nexti

EndSub

22、九九乘法表

PrivateSubCommand1_ClickO

FontSize=13

PrintTab(65);“九九乘法表"

Print

Fori=1To9

Forj=1Toi

PrintTab(j*15);j;i;fi*j;

Nextj

Print

Nexti

EndSub

第七章

1、求3和7的倍數(shù)的數(shù)

PrivateSubCommand1_ClickO

s=0

Fork=1To100

s=s+k*k

Ifs>=10000ThenExitFor

Nextk

Printk-1

Prints-k*k

EndSub

PrivateSubForm_ClickO

Fori=1To100

IfiMod3=0Then

n3=n3+1

Printi;

EndIf

Ifn3Mod20=0ThenPrint

Nexti

Print

Fori=1To100

IfiMod7=0Then

n7=n7+1

Printi;

EndIf

Ifn7Mod20=0ThenPrint

NextI

Print

Print"滿足3的倍數(shù)的數(shù)有";n3;"個"

Print"滿足7的倍數(shù)的數(shù)有";n7;"個"

EndSub

2、100元買100只雞

PrivateSubCommand1_Click0

Dimx%,y%,z%

t1=Time

Forx=0To100

Fory=0To100

Forz=0To100

lfx+y+z=100And3*x+2*y+0.5*z=100Then

Printx,y,z

EndIf

Nextz

Nexty

Nextx

t2=Time

Print"方法一花去";DateDiff(V,t1,t2);"秒時間"

EndSub

PrivateSubForm_ClickO

Dimx%,y%

t1=Time

Forx=0To33

Fory=0To50

If3*x+2*y+0.5*(100-x-y)=100Then

Printx,y,100-x-y

EndIf

Nexty

Nextx

t2=Time

Print"方法二花去DateDlff(V,t1,t2);"秒時間"

EndSub

3、最大公約數(shù)

PrivateSubForm_Click0

m=lnputBox(Henterm:,r)

n=lnputBox(uentern:,r)

Ifm<nThen

t=m:m=n:n=t

EndIf

r=mModn

Whiler<>0

m=n

n=r

r=mModn

Wend

Print"最大公約數(shù)為";n

EndSub

4、課后第二題

PrivateSubForm_Click0

Number=12

r=0.01

WhileNumber<=20

Number=Number*(1+0.01)

n=n+1

Wend

PrintHn=M;n

EndSub

5、課后第六題

PrivateSubCommand1_Click0

Cis

Fori=1To9

PrintTab(50-i);

Forj=1To2*i-1

PrintM*H;

Nextj

Print

Next

EndSub

PrivateSubCommand2_ClickO

Cis

Fori=-3To3

x=4-Abs(i)

PrintTab(50-x);

For|=1To2*x-1

Printn*n;

NextJ

Print

Next

EndSub

PrivateSubCommand3_ClickO

Cis

Fori=1To9

PrintTab(50-3*i);

For|=1Toi

Printj;

Next

Forj=i-1To1Step-1

PrintJ;

Next

Print

Next

EndSub

PrivateSubCommand4_Click0

Cis

Fori=1To9

PrintTab(50-2*i);

k=0

For|=1To2*i-1

Ifj<=iThen

k=k+1

PrintStr$(k);

Else

k=k-1

PrintStr$(k);

EndIf

Next

Print

Next

EndSub

PrivateSubForm_DblClickO

Cis

EndSub

6、課后第六題(2)

PrivateSubCommand1_ClickO

Fori=1To9

Forj=-(i-1)Toi-1

PrintTab(54+6*j);i-Abs(j);

Nextj

Nexti

EndSub

PrivateSubCommand2_Click()

Fori=1To9

PrintTab((9-i)*3+1);1;

Fork=2Toi

Printk;

Nextk

Forj=i-1To1Step-1

Printj;

Nextj

Print

Nexti

EndSub

PrivateSubCommand3_ClickO

Fori=1To9

For|=1Toi

PrintTab(48-3*i+3*j);j;

Next

Form=2Toi

PrintTab(45+3*m);i-m+1;

Next

Print

Next

EndSub

7、課后12題

PrivateSubCommand1_ClickO

Fori=10To99

iN1=iMod10

iN2=lnt(i/10)

Forj=10To99

JN1-JMod10

jN2=lnt(j/10)

m=iN1*10+iN2

n=jN1*10+jN2

Ifi+j=m+nThen

Printi;H+n;j;m;"+n;n;"

k=k+1

IfkMod5=0ThenPrint

EndIf

Next

Next

EndSub

PrivateSubCommand2_Click()

DimmAsInteger

m=lnputBox("enteranumben'1)

a=m\10

b=mMod10

n=b*10+a

Fori=10To99

c=i\10

d=iMod10

|=d*10+c

Ifm+i=n+jThen

Printm;M+M;i;"=H;j;H+M;n

EndIf

Next

EndSub

8、課后1—5題

PrivateSubCommand1_ClickO

Sum=0

Fori=1To100

Sum=Sum+i

Next

Printn1+2+3+...+100=n;Sum

EndSub

PrivateSubCommand2_ClickO

peopleNum=1200000000

r=0.01

DoWhilepeopleNum<2000000000

peopleNum=peopleNum*(1+r)

n=n+1

Loop

Printn;"年后人口增加到”;peopleNum

EndSub

PrivateSubCommand3_ClickO

DimaAsInteger

DimbAsInteger

DimcAsInteger

100

a=lnputBox("entera:")

b=InputBoxf'enterb:")

c=lnputBox(Henterc:H)

Ifa=-1Orb=-1Orc=-1Then

End

EndIf

Ifc<aThen

t=a:a=c:c=t

EndIf

Ifc<bThen

t=b:b=c:c=t

EndIf

Ifa+b>cThen

s=(a+b+c)/2

area=Sqr(s*(s-a)*(s-b)*(s-c))

Print”此三角形面積為:”;area

Else

MsgBox「inputagain:")

GoTolOO

EndIf

EndSub

PrivateSubCommand4_ClickO

income=lnputBox("請輸入您的總收入:(元)")

SelectCaseincome

CaseIs<200

revenue=0

CaseIs<400

revenue=(income-200)*0.03

CaseIs<5000

revenue=(400-200)*0.03+(income-400)*0.04

CaseElse

revenue=(400-200)*0.03+(5000-400)*0.04+(income-5000)*0.05

EndSelect

Print"你要上交的稅收是:revenue

EndSub

PrivateSubCommand5_ClickO

DimdaysAsInteger

days=lnputBox("請輸入一周的某一天,用數(shù)字

SelectCasedays

Case0

y="休息"

Case1,3

y="講計算機(jī)課"

Case2r4

y="講程序設(shè)計課”

Case5

y="進(jìn)修英語"

Case6

y="政治學(xué)習(xí)"

CaseElse

End

EndSelect

Printy

EndSub

9、課后7—9題

PrivateSubCommand1_ClickO

Fora=1To30

Forb=aTo30

Forc=bTo30

lfa*a+b*b=c*cThenPrinta,b,c

Next

Next

Next

EndSub

PrivateSubCommand3_ClickO

DimnAsInteger

DimmAsInteger

n=InputBoxC'entern:,f)

m=lnputBox("enterm:11)

Fori=nTom

k=lnt(i/2)

Sum=0

Forj=1Tok

IfiModj=0Then

Sum=Sum+j

EndIf

Next

IfSum=iThen

Print];”是完全數(shù)?!?/p>

EndIf

Next

EndSub

10、課后10、11題

PrivateSubCommand1_Click0

Cis

PrintH*M;

Fori=1To4

PrintTab(6*i);3*i;

Next

Print

Forj=15To18

Printj;

Fork=3To12Step3

temp=j*k

PrintTab(6*k/3);temp;

Next

Print

Next

EndSub

PrivateSubCommand2_ClickO

DimscoreAsSingle

Number=lnputBox(Henterstudentnumben")

score=lnputBox("enterstudentscore:")

SelectCasescore

Case80To100

pingyu="verygood"

Case60To79

pingyu="good"

Case50To59

pingyu=咋iar”

Case40To49

pingyu="poor"

Case0To39

pingyu="fail”

EndSelect

PrintNumber

Printscore

Printpingyu

EndSub

第九章

1、課后題1

PrivateFunctionMax(a,b,c)

Max=a

Ifb>MaxThenMax=b

Ifc>MaxThenMax=c

EndFunction

PrivateFunctionMin(a,b,c)

Min=a

Ifb<MinThenMin=b

Ifc<MinThenMin=c

EndFunction

PrivateSubCommand1_ClickO

DimxAsSingle

DimyAsSingle

DimzAsSingle

x=lnputBox("請輸入第一個數(shù)值:**)

Printx,

y=lnputBox("請輸入第一個數(shù)值:")

Printy,

z=InputBox「請輸入第一個數(shù)值:”)

Printz

Print"這三個數(shù)中的最大值是:";Max(x,y,z)

Print"這三個數(shù)中的最小值是:";Min(x,y,z)

EndSub

PrivateSubCommand2_ClickO

DimNum1AsSingle

DimNum2AsSingle

DimNum3AsSingle

DimNum4AsSingle

DimNum5AsSingle

Num1=l叩utBox("請輸入第一個數(shù)值:")

PrintNum1,

Num2=lnputBox("請輸入第二個數(shù)值:")

PrintNum2,

Num3=I叩utBox("請輸入第三個數(shù)值:,■)

PrintNum3,

Num4=InputBoxC'請輸入第四個數(shù)值:,f)

PrintNum4,

Num5=InputBoxC'請輸入第五個數(shù)值:,f)

PrintNum5

maxofBnumbers=Max(Num1,Num2,Num3)

Minof3Numbers=Min(Num1,Num2,Num3)

Print”這五個數(shù)中的最大值是:”;Max(Num4,Num5,maxof3numbers)

Print”這五個數(shù)中的最小值是Min(Num4,Num5,Minof3Numbers)

EndSub

PrivateSubCommand3_ClickO

DimNum1AsSingle

DimNum2AsSingle

DimNum3AsSingle

DimNum4AsSingle

DimNum5AsSingle

DimNum6AsSingle

DimNum7AsSingle

Num1=加putBox("請輸入第一個數(shù)值:")

PrintNum1,

Num2=lnputBox("請輸入第二個數(shù)值:")

PrintNum2,

Num3=gputBox("請輸入第三個數(shù)值:")

PrintNum3,

Num4=l叩utBox("請輸入第四個數(shù)值:")

PrintNum4,

Num5=lnputBox("請輸入第五個數(shù)值:

PrintNum5,

Num6=l叩utBox("請輸入第六個數(shù)值:")

PrintNum6,

Num7=lnputBox("請輸入第七個數(shù)值:")

PrintNum7

maxof3numbers=Max(Num1rNum2,Num3)

Minof3Numbers=Min(Num1,Num2,Num3)

maxof5numbers=Max(Num4,Num5,maxof3numbers)

Minof5Numbers=Min(Num4,Num5,Minof3Numbers)

Print”這七個數(shù)中的最大值是:”;Max(Num6,Num7,maxof5numbers)

Print”這七個數(shù)中的最小值是:";Min(Num6,Num7,Minof5Numbers)

EndSub

2、課后題2

PrivateSubfac(nAsInteger,fAsSingle)

f=1

Fori=1Ton

f=f*i

Next

EndSub

PrivateFunctionfunc(nAsInteger)

func=1

Fori=1Ton

func=func*i

Next

EndFunction

PrivateSubCommand1_ClickO

DimaAsInteger

DimbAsInteger

DimcAsInteger

Dimf1AsSingle,f2AsSingle,f3AsSingle

a=lnputBox("enterfirstnumber:0)

Printa,

b=lnputBox("entersecondnumber:11)

Printb,

c=InputBoxf'enterthirdnumben")

Printc

Sum=0

Callfac(a,f1)

Callfac(b#f2)

Callfac(c,f3)

Sum=f1+f2+f3

PrintSum

EndSub

PrivateSubCommand2_ClickO

DimaAsInteger

DimbAsInteger

DimcAsInteger

a=InputBoxf'enterfirstnumber:**)

Printa,

b=lnputBox("entersecondnumber:11)

Printb,

c=lnputBox("enterthirdnumben11)

Printc

Sum=0

Sum=func(a)+func(b)+func(c)

PrintHsum=H;Sum

EndSub

3、課后題3

PrivateFunctiontry(aAsInteger)AsBoolean

IfaMod2=0Thentry=TrueElsetry=False

EndFunction

PrivateSuboddEven(n)

IfnMod2=0Then

Print"TRUE"

Else

Print"False"

EndIf

EndSub

PrivateSubForm_ClickO

DimnumAsInteger

num=lnputBox("enterainteger:11)

,CalloddEven(num)

Printtry(num)

EndSub

4、課后題4

PrivateFunctionAutomorphic(a)

k=10

lfa>10Anda<100Thenk=100

lfa>100Anda<1000Thenk=1000

a2=a*a

Ifa2Modk=aThen

Automorphic=a

EndIf

EndFunction

PrivateSubForm_Click0

Fori=1To1000

PrintAutomorphic(i);

Next

EndSub

5、課后題5

PrivateSubfun(azb,c,x1,x2)

Dimdet

det=(b*b-4*a*c)

Ifdet>=0Then

Ifdet>0Then

det=Sqr(det)

x1=(-b+det)/(2*a)

x2=(-b-det)/(2*a)

Else

x1=-b/(2*a)

x2=x1

EndIf

Else

Print”該方程無實(shí)根?。?!“

EndIf

EndSub

PrivateSubForm_ClickO

DimaAsSingle,bAsSingle,cAsSingle

a=lnputBox("enterfirstnumber:")

Printa,

b=lnputBox("entersecondnumber:11)

Printb,

c=InputBoxf'enterthirdnumben11)

Printc

Callfun(a,b,c,x1,x2)

Print”x1=";x1/'X2=n;x2

EndSub

6、課后題6

PrivateSubForm_ClickO

n=InputBoxf'entern:11)

f1=0:f2=1

Printf1rf2.

Fori=3Ton

f3=f1+f2

IfiMod5=0Then

Printf3

Else

Printf3r

EndIf

f1=f2

f2=f3

Next

Print

Print

Print"第";n;"項的值是:";f3

EndSub

7、課后題7

PrivateSubReadOctalO

num=lnputBox("enteraOctalnumber:11)

num2=Format(num)

Printnum

Printnum2

EndSub

PrivateSubWriteOctalO

,轉(zhuǎn)換成十六進(jìn)制HexO

,如:10(十進(jìn)制):Hex(10)=A

,轉(zhuǎn)換成8進(jìn)制OctO

'如:10(十進(jìn)制):Oct(10)=12

DimnumAsSingle

num=lnputBox("enteraDecnumber:11)

num2=Oct$(num)

Printnum

Printnum2

EndSub

PrivateSubCommand1_Click0

CallReadOctal

EndSub

PrivateSubCommand2_ClickO

CallWriteOctal

EndSub

PrivateSubDectoBin_ClickO

,轉(zhuǎn)換成2進(jìn)制,使用下面的方法

,采用連除2取余數(shù),將一個十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制數(shù)

DimDecAsInteger,輸入一個十進(jìn)制數(shù)

DimBinAsString'轉(zhuǎn)換為二進(jìn)制表示

DimresAsInteger

DimiAsInteger

Dec=Val(lnputBoxCx="))

Forml.Print”十進(jìn)制數(shù):”;Dec

Do

res=DecMod2,求出除以2的余數(shù)

Bin=res&Bin

Dec=Dec\2

LoopWhileDec<>0

Forml.Print"轉(zhuǎn)換為二進(jìn)制數(shù)為:”;Bin

EndSub

PrivateSubDecToOct_Click0

,轉(zhuǎn)換成8進(jìn)制OctO

,如:10(十進(jìn)制):Oct(10)=12

,轉(zhuǎn)換成8進(jìn)制,使用下面的方法

,采用連除8取余數(shù),將一個十進(jìn)制數(shù)轉(zhuǎn)換為8進(jìn)制數(shù)

DimDecAsInteger,輸入一個十進(jìn)制數(shù)

DimOctalAsString'轉(zhuǎn)換為二進(jìn)制表示

DimresAsInteger

DimiAsInteger

Dec=Val(lnputBoxCx="))

Forml.Piint”十進(jìn)制數(shù):”;Doc

Do

res=DecMod81求出除以2的余數(shù)

Octal=res&Octal

Dec=Dec\8

LoopWhileDec<>0

Forml.Print”轉(zhuǎn)換為八進(jìn)制數(shù)為:Octal

EndSub

8、課后題8

PrivateSubsumnO

Sum=0

Fori=1To100

Sum=Sum+1/i

Next

Print“sum*Sum

EndSub

PrivateSubForm_ClickO

Callsumn

EndSub

9、課后題9

PrivateSubpaiValue(n,pai)

Sum=0

j=1

Fori=1Ton

Sum=Sum+j/(2*i-1)

i=-i

Next

pai=Sum*4

EndSub

PrivateSubForm_ClickO

DimnAsInteger

n=InputBoxf'inputn:,f)

CallpaiValue(n,pai)

Printpai

EndSub

10、p236

OptionExplicit

Dimtest_arrayOAsInteger

StaticSubsqval(a)

a=Sqr(Abs(a))

EndSub

PrivateSubForm_ClickO

FontSize=26

DimiAsInteger,jAsInteger

ReDimtest_array(1To5,1To3)

test_array(5,3)=-36

Printtest_array(5,3)

Callsqval(test_array(5,3))

Printtest_array(5,3)

EndSub

11、231頁

OptionExplicit

DimarrOAsInteger

DimiAsInteger

DimjAsInteger

StaticSubPrintout(aOAsInteger)

DimrowAsInteger,colAsInteger

Forrow=LBound(a,1)ToUBound(a,1)

Forcol=LBound(az2)ToUBound(a,2)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論