资源描述:
《vb程序编辑题》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、一、求和、求均值,最大、最小值;1.求和及平均值(1)每一行的和及平均值Dimsumasinteger,sumlasintegerFori=1To4sum=0Forj=1To4sum=sum+a(i,j)NextjPrintsum/4—每行平均位Nexti2.找最值DimmaxAsInteger,minAsIntegermax=a(l):min=a(l)Fori=2To10Ifmax<=a⑴Thenmax=a(i)EndIfIfmin>=a(i)Thenmin=a(i)EndIfNextiPrintmax;min二、判断字母、数字、其他字符(1)If...ElseIf...:Private
2、SubCommand1Click()DimaAsString*1a=Text1IfUCase(a)〉="A〃AndUCase(a)〈=〃Z〃ThenText1.Text=a&〃是字母〃Elselfa>="0"Anda<="9"ThenText1.Text=a&〃是数字"ElseTextl.Text=a&〃是其仑字符〃EndIfEndSub(2)SelectCase:PrivateSubCommand2_Click()DimaAsString*1a=TextlSelectCaseaCaseaioz,AioLTextl.Text=a&〃是字母"Case"0"To〃9〃Textl.Text=a&
3、〃是数字〃CaseElseTextl.Text=a&〃是其它字符〃EndSelectEndSub三、计数(统计各个字母个数、各个数字个数)(1)统计各个字母个数:【实验十】2.PrivateSubFormClick()FontSize=20CisDima%(65To90),b$,cb=I叩utBox(〃输入一串字符串(字母):〃)Print〃输入的字母串为";bFori=1ToLen(b)c=Asc(UCase(Mid(b,i,1)))a(c)=a(c)+1NextiFori=65To90Ifa(i)<>0ThenPrintChr(i);"的个数为:";a(i)NextiEndSub(2)
4、各个数字个数编写一程序,用随机函数产生(0-99)范围的随机整数,统计个位上数字分别为1,2,3,4,5,6,7,8,9,0的数的个数。PrivateSubFormClick()Dima(100),b(100)AsIntegerFori=1To100a(i)=Int(Rnd*100)Printa(i);IfiMod10=0ThenPrintEndIfNextFori=1To100b(i)=a(i)Mod10Printb(i);IfiMod10=0ThenPrintEndIfSelectCaseb(i)Caseb(i)=0aO=aO+1Caseb(i)=1al=al+1Caseb(i)=2a
5、2=a2+1Caseb(i)=3a3=a3+1Caseb(i)=4a4=a4+1Caseb(i)=5a5=a5+1Caseb(i)=6a6=a6+1Caseb(i)=7a7=a7+1Caseb(i)=8a8=a8+1Caseb(i)=9a9=a9+1EndSelectNextiPrintPrint"a0="aOPrint"al=〃alPrint"a2="a2Print〃a3=〃a3Print'Wa4PrintWa5Print〃a6=〃a6Print"a7="a7Print"a8=〃a8Print'Wa9EndSub四、回文数、水仙花数、百元买百鸡(1)回文数(设n是一任意自然数。若将n的各
6、位数字反叫排列所得自然数nl与n相等,则称n为一
7、叫文数。例如,若n=1234321,则称n为一回文数;似若n=1234567,则n不是回文数。)PrivateSubFormLoad()Dim1AsIntegera=lnt(InputBox(〃请输入一个正整数"))1=Len(a)Fori=1To1/2IfMid(a,i,1)=Mid(a,1+1-i,1)ThenCisPrintPrintTab(12);a&"是回文数"ElseCisPrintPrintTab(12);a&"不是回文数"EndIfNextiEndSub(2)水仙花数:水仙花数是指一个n位数(n>3),它的每个位上的数字的n
8、次幂之和等于它木身。(例如:1A3+5A3+3A3=153)PrivateSubCommand1Click()DimxAsIntegerDimg%,s%,b%x=153g=xMod10s=x10Mod10b=x100Ifg"3+s"3+b"3=xThenForml.Print〃水仙花数〃ElseEorml.Print"no"EndIfEndSub(3)百元买百鸡14题:编写程序解决百钱买百鸡M题:公鸡5元/只,母鸡3