2024-10-22 05:34:23
利用VB,编写一个3*4的
1、输入
2、初始化数组并定义变量类型。
3、输入i和j。
4、输出第i行第j列的元素。
5、编译、运行。
注意事项:
在Visual Basic 6.0中,采用面向对象程序设计方法(Object-Oriented Programming),把程序和数据封装起来作为一个对象,每个对象都是可视的。
2024-10-22 07:20:37
Option Base 1
Private Sub Command1_Click()
Dim a(3, 4) As Integer, i As Integer, j As Integer '定义一个二维数组,i循环代表行下标,j循环代表列下标
Dim s As Long, ave As Single 's存放数组元素的和值,ave为平均值
s = 0
For i = 1 To 3
For j = 1 To 4
a(i, j) = Int(Rnd * 101) '给这个二维数组赋值为100以内的随机整数
Print a(i, j);
s = s + a(i, j) '求所有元素的合值
Next j
Print
Next i
ave = s / 12 '求平均值
Print "二维数组的元素的和=" & s
Print "二维数组的元素平均值=" & ave
End Sub
2024-10-22 07:25:19
Private Sub Command1_Click()
Dim i As Integer, j As Integer, A(1 To 3, 1 To 4) As Integer, X As Integer
'i、j、X 是变量,A(1 To 3, 1 To 4)是二维数组变量
For i = 1 To 3 'i是循环变量,这里循环3次
For j = 1 To 4 'j是循环变量,这里循环4次
Randomize '刷新随机数种子
A(i, j) = Int(Rnd * 90 + 10) '产生随机数,存储在A数组中
X = X + A(i, j) '计算数组的和
Print A(i, j) & " "; '打印数组的值
Next j 'j循环结束
Print '打印换行
Next i 'i循环结束
Print '设置一个空行
Print "3*4数组的和 = " & X '打印数组的和
Print "平均值 = " & Round((X / ((i - 1) * (j - 1))), 2) '打印平均值,取小数后二位
End Sub
2024-10-22 06:28:25
Private Sub Command1_Click()
Print "请输入一个3*4的二维数组"
Dim a(3, 4)
For i = 1 To 3
For j = 1 To 4
x = Val(InputBox("请输入a(" & i & "," & j & "):"))
a(i, j) = x
s = s + a(i, j)
Print a(i, j),
Next j
Next i
Print "元素总和="; s
Print "平均值="; s / 12
End Sub