设计程序的题目,请高手帮忙回答
? Bonnie ヾ
2024-11-15 10:36:28
最佳回答
1 '求1到100间能被6整除的整数个数 private sub command1_click() dim i as integer dim count as integer for i = 1 to 100 if i mod 6 = 0 then count = count + 1 next i print "1到100间能被6整除的整数个数:"; count end sub 2 '输入一个正整数,判断其奇偶性并输出判断结果 private sub command2_click() dim a as string dim n as long a = inputbox("输入一个正整数", "输入") n = clng(a) if n mod 2 = 0 then print n; "是偶数" else print n; "是奇数" end if end sub 3 '输入一个数,判断其是否为整数并输出判断结果 private sub command3_click() dim a as string dim n as long a = inputbox("输入一个数", "输入") if not **numeric(a) then print a; " 不是数" elseif instr(1, a, ".") = 0 then print a; " 是整数" else print a; " 不是整数" end if end sub 4 '输入两个正整数,求它们的最大公约数并输出 private sub command4_click() dim m as long dim n as long dim r as long dim a as string a = inputbox("输入一个正整数", "输入") m = clng(a) a = inputbox("输入一个正整数", "输入") n = clng(a) if n > m then r = m m = n n = r end if dim m1 as long dim n1 as long m1 = m n1 = n r = m1 mod n1 do while r <> 0 m1 = n1 n1 = r r = m1 mod n1 loop print m; "和"; n; "的最大公约数: "; n1 end sub 5 '从键盘输入三角形的三条边的边长,判断其能否构成一个三角形并输出判断结果 private sub command5_click() dim a as single dim b as single dim c as single dim s as string s = inputbox("输入一个数", "输入") a = csng(s) s = inputbox("输入一个数", "输入") b = clng(s) s = inputbox("输入一个数", "输入") c = clng(s) if a > 0 and b > 0 and c > 0 and a + b > c and a + c > b and b + c > a then print a; ","; b; ","; c; "可以构成三角形" else print a; ","; b; ","; c; "不能构成三角形" end if end sub'6求10!的值并输出private sub command6_click()dim i as longdim n as longn = 1for i = 1 to 10n = n * inext iprint "10! ="; nend sub7'求1-2+3-4+……-n的计算结果并输出private sub command7_click()dim s as stringdim i as longdim n as longdim sum as longs = inputbox("输入一个正整数", "输入")n = clng(s)for i = 1 to nif i mod 2 = 0 thensum = sum - ielsesum = sum + iend ifnext iprint sumend sub 20210311