08级程序填空编程题 - 图文

更新时间:2023-11-10 12:00:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

程序填空题

1.

下面程序打印如图所示的杨辉三角形。阅读程序,请填空。

Private Sub Form_click()

Dim a(9, 9) As IntegerFor i = 0 To 9

a(i, i) = 1a(i, 0) = 1Next i

For i = 2 To 9

M = i -1

For j = 1 To M

a(i, j) = a(i -1, j) + a(i -1, j -1)Next jNext i

For i = 0 To 9

For j = 0 To i

Print a(i, j);Next jPrintNext iEnd Sub

2.下面的程序是进行加、减、乘、除的程序,运行界面如下图。输入两个操作数和一个运算符,根据运算符决定所进行的运算。阅读程序,请填空。

Private Sub Command1_Click()

Dim a As Integer, b As Integera = Val(Text1.Text)b = Val(Text3.Text)'以下判断运算符op = Text2

Select Case opCase \

r = a + bCase \

r = a -bCase \

r = a * b

Case \

If b = 0Then

MsgBox \除法运算的操作的除数不能为0\Text3.Text = \Exit SubEnd Ifr = a / bCase Else

MsgBox \运算符非法,请重新输入\Text2.Text = \Text2.SetFocusExit Sub

End SelectText4 = rEnd Sub

5. 下面是比较互换法对数据进行升序排序的程序,阅读下面程序并填空。

Private Sub Command1_Click()

Dim S(1 To 6) As IntegerFor i = 1 To 6

S(i) = InputBox(\输入S(\的值\Print S(i);Next iPrint

For i = 1 To 5

For j = i + 1 To 6

If S(j) > S(i)Then

t = S(i): S(i) = S(j): S(j) = tEnd IfNext jNext i

For i = 1 To 6

Print S(i);Next iEnd Sub

6. 下面程序的作用是用InputBox函数输入一个整数,然后判断能否同时被2,5和7整除,如果能则输出该数及平方值。请填空。

Private Sub Command1_Click()Dim numX As Integer

numX = Val(InputBox(\请输入一个整数\

If numX Mod 2 = 0 And numX Mod 5 = 0 And numX Mod 7 = 0Then

Form1.Print numX, numX ^ 2Else

Form1.Print \该数不符合条件\End IfEnd Sub

7. 下列程序计算Sn的值。Sn=a+aa+aaa+?+aaa?a,其中最后一项为n个。例如:a=5 ,n=4时,则

Sn=5+55+555+5555。请在空白处填入适当的内容,将程序补充完整。

Private Sub Command1_Click()

Dim a As Integer, n As Integer, Cout As IntegerDim Sn As Long, Tn As LongCout = 1Sn = 0Tn = 0

a = InputBox(\请输入a的值:\n = InputBox(\请输入n的值!\Do

Tn = Tn * 10 + aSn = Sn + TnCout = Cout + 1

Loop While Cout <= nPrint a, n, SnEnd Sub

8. 以下是一个计算矩形面积的程序,调用过程计算矩形面积,请将程序补充完整。

Sub Area(l, w, S As Double)

S = l * wEnd Sub

Private Sub Command1_Click()

Dim M, N, S As Double

M = InputBox(\M = Val(M)

N = InputBox(\N = Val(N)

Call Area(M, N, S)Print S

End Sub

把上述程序改写如下也正确,为什么?

Sub Area(l As Single, w As Single, S As Double)

S = l * wEnd Sub

Private Sub Command1_Click()

Dim M As Single, N As Single, S As DoubleM = InputBox(\N = InputBox(\Call Area(M, N, S)Print SEnd Sub

9.下面的程序用“选择法”将数组a中的10个整数按降序排列,请将程序补充完整。

Option Base 1

Private Sub Command1_Click()

Dim a As Variant

a = Array(68, 45, 324, 528, 439, 387, 87, 875, 273, 823)

For i = 1 To 9

ii = i

For j = i + 1 To 10

If a(j) >= a(ii)Then ii = jNext jt = a(ii)a(ii) = a(i)a(i) = tNext i

For i = 1 To 10

Print a(i)Next iEnd Sub

10.以下程序的功能是:生成20个200到300之间的随机整数,输出其中能被5整除的数并求出它们的和。请填空。

Private Sub Command1_Click()

For i = 1 To 10

x = Int(Rnd() * 50 + 200)Print x

If x Mod 5 = 0Then

s = s + xEnd IfNext i

Print \=\sEnd Sub

11.下面的程序用“冒泡”法将数组number中的10个整数按升序排列,请将程序补充完整。

Option Explicit

Private Sub Command1_Click()

Static number(1 To 10) As IntegerDim i As Integer, j As IntegerDim t As IntegerFor i = 1 To 10

number(i) = InputBox(\输入数据\Print number(i);Next iPrint

For i = 1 To 10

For j = 1 To 10 -i

If number(j) > number(j + 1) Thent = number(j + 1)

number(j + 1) = number(j)number(j)= tEnd IfNext jNext i

For i = 1 To 10Print number(i);Next iEnd Sub

12.下面的程序是将一组数左移一位的程序,请将程序补充完整。

Private Sub Command1_Click()

Dim x(1 To 6) As IntegerFor i = 1 To 6

x(i) = i * 3

Print x(i); \Next iPrintt = x(1)

For i = 1 To 5

x(i) = x(i + 1)Next ix(6)= t

For i = 1 To 6

Print x(i); \Next iEnd Sub

本文来源:https://www.bwwdw.com/article/m5zv.html

Top