VB编程题经典案例(7页).doc





《VB编程题经典案例(7页).doc》由会员分享,可在线阅读,更多相关《VB编程题经典案例(7页).doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-VB编程题经典案例-第 7 页VB经典案例1输入3个数,输出最大的数 X=val(text1) y=val(text2) z=val(text3) if x=y then if x=z then print x else print z end ifelse if y=z then print y end if 2有一元二次方程:aX2+bX+c=0,依次输入a,b,c,判断此方程是否有实根a=val(text1) b=val(text2) c=val(text3) If b*b-4*a*c=0 then print “有实根” else print “无实根” end if3输入一个成绩,
2、若大于等于60,则用消息框显示“恭喜!成绩通过!”,若小于60,则弹出消息框显示“抱歉!成绩没有通过!”N=val (text1) if n=60 then msgbox”恭喜!成绩通过!” else msgbox “抱歉!成绩没有通过!” end if 4输入一年份,判断它是否为闰年,并显示有关信息(判断闰年的条件是:年份能被4整除但不能被100整除,或者能被400整除)y=val(text 1) if y mod 4 =0 and y mod 100 = 0 then print “y是闰年” else print y “不是闰年” end if 5输入学生的百分制成绩,转换输出为五级制成
3、绩,90100分转换为优秀,8089转换为良好,7079转换为中等,6069转换为及格,060转换为不及格。If mark =90 then grade= 优 else If mark =80 then grade =良 else If mark =70 then grade =中 else If mark =60 then grade =及格 else grade=”不及格”6随机产生一个三位正整数,然后逆序输出,产生的数与逆序数同时显示。例如,产生246,输出是642。n=int(r n d *900+100) dim x%,a%,b%,c% a=x mod 10 b=int(x mod
4、100)/10) c=int(x/100 ) print x;a*100+b*10+c7 输入两个整数,求它们的最大公约数。Function gcd %(by val m%,by val n%) if mn then t=m : m=n:n=t R= m mod n do while (r 0) m=n : n=r :r= mod n loop gcd =n end function8 编程求200-400范围内5的倍数或7的倍数之和。dim s%,i% s=0 For i =200 to 400 if i mod 5 =0 or i mod 7 =0 then s=s+i end if ne
5、xt i print s 9 计算100300之间所有能被3和7整除的数之和dim s%,i% s=0 for i=100 to 300 If i mod 3 =0 and i mod 7 =0 then s=s+i end if next i print “s=” &s 10 分别统计1-100中,满足3的倍数、7的倍数的数各有多少。Dim n1%,n2% ,i% n1=0:n2=0 For i=1to 100 if i mod 3=0 then n1=n1+1 if i mod 7=0 then n2=n2+1 next i print n1,n211 某次歌曲大奖赛,有7个评委。如果分别
6、输入7个评委对某个参赛者的打分数,按照去掉一个最高分和一个最低分的计算办法,求出该参赛者的平均得分。Dim a(6) as integer i%,max%,min%,sum% a(0)=val(text1.text) 省略 a(6)=val(text7.text) sum=a(0)+a(1)+a(2)+a(3)+a(4)+a(5)+a(6) max=a(0) min=a(0) for i =1 to 6 if mina(i) then min=a(i) If maxa(i) then max=a(i) sum=sum+a(i) next i print “平均分”;(sum-min -max)
7、/512 输入一串字符,统计其中字母A出现的次数。dim s$,i%,n% s=text1 n=0 for i=1 to len(s) c=mid(s,i,1)If c=”A” OR c=”a” then n=n+1 next i print n 13 我国目前有13亿人口,按人口年增长率0.8%计算,多少年后我国人口将超过26亿。x=13 n=0 do while x26 x=x*1.008 n=n+1 loop print “年数为:”;n;”人数为:”;x m=log(2)/log(1.008) if int(m)m then m= int(m)+1 print m 14 小猴有桃若干,
8、第一天吃掉一半多一个;第二天吃剩下桃子的一半多一个;以后每天都吃尚存桃子的一半多一个,到第7天只剩一个,问小猴原有桃多少Dim n%,i% x=1 for i=6 to 1 step -1 x =2*(x+1) print x next i 15 求100以内的素数Dim m%,i%,tag as boolean for m=3 to 100 step 2 tag=true for i=2 to m-1 if m mod i=0 Then tag=false next i If tag=true then print m&”是素数” else print m&”不是素数”End if next
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 编程 经典 案例

限制150内