石家庄铁道大学vb作业答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.113页编程题第一题

(1)编写程序,建立一个数组,并通过Rnd函数(该函数返回一个0到1之间的数)为每个数组元素赋一个1到100之间的整数。然后显示所有小于60的元素。

参考代码:

Private Sub Form_Click()

Dim a(1 To 20) As Integer, i As Integer

Dim j As Integer

j = 0 '用来表示小于60的个数

'建立两个picture,用于显示随机产生的数组和小于60的所以元素

Picture1.Print "产生的数组为:"

Picture1.Print

Picture2.Print "其中小于60的元素有:"

Picture2.Print

For i = 1 To 20

a(i) = Int(Rnd * 100 + 1)

Picture1.Print a(i);

If i Mod 10 = 0 Then Picture1.Print '10个数换行

If a(i) < 60 Then

j = j + 1

Picture2.Print a(i); " ";

If j Mod 10 = 0 Then Picture2.Print '10个数换行

End If

Next i

End Sub

2.113页编程题第二题

(2)编写程序,随机产生10个二位数,放入数组A中,从中选出一个最大的和一个最小的数,并显示出来。

参考代码:

Private Sub Form_Click()

Dim a(1 To 10) As Integer

Dim max As Integer, min As Integer, i As Integer

For i = 1 To 10

a(i) = Int(Rnd * 90 + 10)

Picture1.Print a(i);

If i Mod 5 = 0 Then Picture1.Print

Next i

max = a(1)

min = a(1)

For i = 2 To 10

If a(i) > max Then max = a(i)

If a(i) < min Then min = a(i)

Next i

Label1.Caption = "最大数为:" & max

Label2.Caption = "最小数为:" & min

End Sub

3.113页编程题第五题

(5)利用随机数生成两个4×4的矩阵A和B,前者范围为30-70,后者范围为101-135。要求:

①将两个矩阵相加,结果放入C矩阵。

②将矩阵A转置后放入D矩阵。

③求C矩阵中元素的最大值和下标。

④以下三角形式显示A,上三角形式显示B。

⑤将矩阵B第一行与第三行对应元素交换位置并输出。

参考代码:

Dim a(1 To 4, 1 To 4) As Integer

Dim b(1 To 4, 1 To 4) As Integer

Dim c(1 To 4, 1 To 4) As Integer

Dim d(1 To 4, 1 To 4) As Integer

Dim e(1 To 4, 1 To 4) As Integer

Private Sub Form_Load()

Show

Picture1.FontSize = 10

Picture2.FontSize = 10

Picture1.Print "A矩阵:"

Picture1.Print

Picture2.Print "B矩阵:"

Picture2.Print

Randomize (5)

For i = 1 To 4

For j = 1 To 4

a(i, j) = Int(Rnd * 40 + 30)

b(i, j) = Int(Rnd * 35 + 101)

Picture1.Print a(i, j); " ";

Picture2.Print b(i, j); " ";

Next j

Picture1.Print

Picture2.Print

Picture1.Print

Picture2.Print

Next i

End Sub

①将两个矩阵相加,结果放入C矩阵。Private Sub Command1_Click()

Picture3.Print "C矩阵:"

Picture3.Print

For i = 1 To 4

For j = 1 To 4

c(i, j) = a(i, j) + b(i, j)

Picture3.Print c(i, j); " ";

Next j

Picture3.Print

Picture3.Print

Next i

End Sub

②将矩阵A转置后放入D矩阵。

Private Sub Command2_Click()

For i = 1 To 4

For j = 1 To i

t = a(i, j)

a(i, j) = a(j, i)

a(j, i) = t

Next j

Next i

Picture4.Print "A转置后:"

Picture4.Print

For i = 1 To 4

For j = 1 To 4

d(i, j) = a(i, j)

Picture4.Print a(i, j); " ";

Next j

Picture4.Print

Picture4.Print

Next i

End Sub

③求C矩阵中元素的最大值和下标。

Private Sub Command3_Click()

Max = c(1, 1)

t1 = 1

t2 = 1

相关文档
最新文档