




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一、求和、求均值,最大、最小值;1. 求和及平均值(1) 每一行的和及平均值 dim sum as integer, suml as integer for i = 1 to 4sum = 0for j = 1 to 4sum = sum + a(i, j)next jprint sum / 4每行平均位next i2. 找最值dim max as integer, min as integer max = a(l): min = a(l)for i = 2 to 10 if max <= a then max = a(i)end ifif min > =a(i) thenmin
2、= a(i)end ifnext iprint max; min二、判断字母、数字、其他字符(1) if.elseif.:private sub command1 click()dim a as string * 1a = text 1if ucase(a) = "a and ucase(a) = z then text 1. text = a & 是字母el self a >= "0" and a <= "9" then text 1. text = a & 是数字"elsetextl.text = a
3、& 是其仑字符end ifend sub(2) select case :private sub command2_click()dim a as string * 1a = textlselect case acase a io z , a io ltextl. text = a & 是字母"case "0" to 9textl. text = a & 是数字case elsetextl.text = a & 是其它字符end selectend sub三、计数(统计各个字母个数、各个数字个数)(1) 统计各个字母个数:【实验十】
4、2.private sub formclick()fontsize = 20cisdim a%(65 to 90),b$, cb = i叩utbox(输入一串字符串(字母):)print 输入的字母串为";b for i = 1 to len(b)c = asc(ucase(mid(b, i, 1) a(c) = a(c) + 1 next ifor i = 65 to 90if a(i) <> 0 then print chr(i);"的个数为:"a(i) next i end sub(2) 各个数字个数编写一程序,用随机函数产生(0-99)范围的随
5、机整 数,统计个位上数字分别为1, 2, 3, 4, 5, 6, 7, 8, 9, 0的数的个数。private sub form click()dim a(100), b (100) as integerfor i = 1 to 100a(i) = int(rnd * 100)print a(i);if i mod 10 = 0 thenprintend ifnextfor i = 1 to 100b(i) = a(i) mod 10print b (i);if i mod 10 = 0 thenprintend ifselect case b(i)case b(i) =0ao = ao +
6、 1case b(i) = 1al = al + 1case b(i) =2a2 = a2 + 1case b(i) = 3a3 = a3 + 1case b(i) = 4a4 = a4 + 1case b(i) = 5a5 = a5 + 1case b(i) = 6a6 = a6 + 1case b(i)=7a7 = a7 + 1case b(i)=8a8 = a8 + 1case b(i)=9a9 = a9 + 1end selectnext iprintprint "a0="aoprint "al=alprint "a2="a2print
7、 a3=a3print 'wa4print wa5print a6=a6print "a7="a7print "a8=a8print 'wa9end sub四、回文数、水仙花数、百元买百鸡(1) 回文数(设n是一任意自然数。若将n的各位数 字反叫排列所得自然数nl与n相等,则称n为一|叫文 数。例如,若n=1234321,则称n为一回文数;似若 n=1234567,则n不是回文数。)private sub formload()dim 1 as integera = lnt (inputbox(请输入一个正整数")1 = len(a)for
8、 i = 1 to 1 / 2if mid (a, i, 1) = mid (a, 1 + 1 - i, 1) thencisprintprint tab (12) ; a & "是回文数"elsecisprintprint tab (12); a & "不是回文数"end ifnext iend sub(2) 水仙花数:水仙花数是指一个n位数(n>3),它 的每个位上的数字的n次幂之和等于它木身。(例 如:1a3 + 5a3+3a3 = 153)private sub command1 click()dim x as intege
9、rdim g%, s%, b%x = 153g = x mod 10s = x 10 mod 10b = x 100ifg"3+s"3+b"3=x thenfor ml. print 水仙花数elseeorml.pri nt "no"end ifend sub(3) 百元买百鸡14题:编写程序解决百钱买百鸡m题:公鸡5元/只, 母鸡3元/只,小鸡一元买3只,用100元买100只鸡, 问有哪些购买方案?(p34)private sub commandl_click()dim a, b, c as integerdim aconst, bconst
10、 as integerdim sum as integeraconst = int(100 - (100 / 3) / 5) + 1for a = 0 toaconst bconst = lnt(100 - a * 5) / 3) + 1 for b = 0 tobconstc = 100 - a - bif not (c mod 3) then sum =a*5+3b+c/3if sum =100 thenprint 公鸡 & a, 付鸡& b,小鸡 & celsetf sum > 100 thenexit i?orend ifend ifnextnextend
11、 sub五、数组排序(冒泡、选择),交换(1) 数组排序(冒泡、选择)1.胃泡:private sub conimand2_click()fontsize = 15cisprint "随机产生的原数组为:" n = i叩utbox ("数组元素的个数n: )redima(n)for i = 1 to ubound(a) a(i) = lnt(rnd * 200+1)print a(i);next i printfor i = 1 to ubound(a) - 1 p = ifor j = i + 1 to ubound(a)if a(j) a(p) then p
12、= jnext j t = a(i)a(i) = a(p)a(p) = t next iprint "排序后数组为:"for i = 1 to ubound(a)print a(i);next i printend sub2. 选择:private sub command1 click()fontsize = 15 cisprint 随机产生的原数组为: n = inputbox ("数组元素的个数n:")redima(n)for i = 1 to ubound(a) a(i) = int(rnd * 200 + 1)print a(i);next i
13、printfor i = 1 to ubound(a) - 1 p = ifor j = i + 1 to ubound(a)if a(j) < a(p) then p = jnext j t = a(i)a(i) = a(p)a(p) = t next iprint 选择法排序后数组为:"for i = 1 to ubound(a)print a(i);next i printend sub (2) 交换1.【实验七】1.private sub form_click()dim i%, a$, b$, c$a = inputbox (请输入一个任意整数:) print 输入的整
14、数为a for i = 1 to len(a)b = mid (a, i, l)print b & ,; c = b & c next iprint "逆向排列数为:";c end sub2.【实验十】1. 1private sub eormclick()fontsize = 20cisdim i%, a%(10), t%randomi zeprint 随机产生的10个数字为for i = 1 to 10 a(i) = int(knd * 101 + 200)print a;tf i mod 5=0 then printnext ifor i = 1 to
15、5 t = a(i) : a(i) = a(i + 5):next iprint 交换后的数字为:"for i = 1 to 10print a(i);if i mod 5=0 then printnext iend sub六、阶乘、阶乘和组合数。(1) 阶乘1.x%=inputbox( “”)6dim s as integer s=0for i=l to x-15if x mod i=0 then s二s+i 0+1+2+3 end ifnext i 2345if s=x thenprint “yes”elseprint “no”end if2.【实验十三】private sub
16、form click()dim a%, s!fontsize = 20a(i + 5) = tn = i叩utbox(输入一个正狼数s = fac(n)print n & "!,& send subpublic function fac(k) as singledim i%fac = 1for i = 1 to kfac = fac * inext iend function(2) 阶乘private sub form clickodim x as long, y as double, z as double print tab (15) ; l-10 的阶乘 y =
17、 ifor x = 1 to 10y=y 氺 x: z = z + yprint x; ! = ; y:next xprint "l!+2!+3!+4!+5!+6!+7!+8!+9!+10!=" z end sub3. 阶乘和private sub command1 click ()for i = 1 to 10sum = sum + jiecheng(i)nextprint sumend subfunction jiechcng(num)jiecheng = 1for i=l tonum jiecheng = jiecheng * i nextend function七、
18、素数;斐波那契数列(1) 斐波那契数列:1 .题fl输!li斐波那契级数1、2、3、5、8、13-., 当某项数位人于或等于30000时结來。此级数项的规律 足:前两项的值各为1,从第3项起,每-项是前两项 的和。(要求一行输出6项)。private sub formclick()dim a&, b&, c&, i%a = 1b = 1i = 2print a; b;do c = a + bif c <= 30000 thenprint c;elseexit doend ifa = bb = ci = i + 1if i mod 6=0 then printloo
19、pend sub2题目:输出斐波那契级数1、1、2、3、5.的前30 项要求每行输出5个(川数组完成)。【提示】斐波那契 级数列的特点是:第一、第二都是1,从第三项开始, 前面相邻两项之和,构成后一项。即:a (n) =a (n-1) +a (n2).private sub formclick()fontsize = 20dim a&()kedimaa(l) = 1: a(2) = 1cisprint a(l) ; a(2);i = 3doredim preserve a(i)a(i) = a(i - 2) + a(i - 1)print a(i);if i mod 5=0 then
20、print if i = 30 then exit do i = i + 1loopend sub (2) 素数:方法一:一个数n适素数的条件:不能被2 n-1憋除用for next语句dim t as integer, n as integer n=val (inputbox(")for 1=2 to n-1if n mod 1=0 then exit for 如果能被 2 n-l 屮任 何一个数整除,则不是素数,跳出for循环 next tif i >= n then如果正常跳出for循环,则1跳出循环 for后的值应该是n,所以满足这个条件 print n & &
21、quot;是素数"elseprint n & 不是素数end if方法二:(一般都是用这种方法)一个数n是素数的条件:不能被2sqr(n)整除,1. 用 for next 语句dim i as integer, n as integern=val(inputbox("")for 1=2 to int(sqr(n)if n mod 1=0 then exit fornext tif 1 >int (sqr(n) thenprint n & 是素数elseprint n & 不是素数end if2. 【实验十三过程】private sub
22、 form_click()dim n%fontsize = 20n = i叩utbox(请输入一个正整数n: )if prime(n) = true thenprint n; 是素数elseprint n; 不是素数end tfend subfunction prime(n%) as boolean d = truefor i = 2 to n - 1 tf n mod i = 0 thend = false exit forend if nextprime = dend function3. dim x as integer dim n as intgern=0统计w子的个数 x=inputbox( “”)for k=l to x 表示因子的范围if x mod k=0 then满足条件说明k为一个因子 n=n+lend ifnext kif n=2 thenprint x;”是素数” print “不足素数”end if八、顺序文件的读写操作(p25)(1) 读:private sub coinmand2_click()dim i%op
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年汽车租赁合同范本
- 2025年租车带司机服务合同模板
- 2025标准个人租房租赁合同样本
- 2025财产委托管理合同模板
- 2025包装盒生产合同模板
- 2025年土地流转合同样本
- 2025订购绿化苗木合同模板
- 2025物业管理服务合同范本
- 2025合同能源托管协议范本
- 2025咖啡店承包合同协议书
- 美国加征关税从多个角度全方位解读关税课件
- 期中(试题)-2024-2025学年人教精通版(2024)英语三年级下册
- 一例脂肪液化切口的护理
- 2025-2030中国煤焦油杂酚油行业市场发展趋势与前景展望战略研究报告
- 2025届嘉兴市高三语文二模作文解析:智慧不会感到孤独
- 2025中考英语热点话题阅读《哪吒2魔童闹海》
- 定额〔2025〕1号文-关于发布2018版电力建设工程概预算定额2024年度价格水平调整的通知
- 《思想政治教育方法论》考研(第3版)郑永廷配套考试题库及答案【含名校真题、典型题】
- UL9540A标准中文版-2019储能系统UL中文版标准
- 一种基于STM32的智能门锁系统的设计-毕业论文
- 末端产品介绍
评论
0/150
提交评论