下列程序代码将整型动态数组x定义为具有20个元素的数组(数组元素的下标从1到20),并给数组的所有元素赋值1。请完善程序。 Dim x( ) As IntegerPrivate Sub Cmd1_Click() ReDim For i = 1 To 20 x(i) = 1 Print x(i) Next iEnd Sub
举一反三
- 使用下列命令定义了数组x后,所有数组元素具有相同的 ( )Dim x(99) As IntegerFor i = 0 To UBound(x) x(i) = iNext i A: 存储地址 B: 下标 C: 值 D: 类型
- 使用数组x输出10个1-100之间的随机整数(包括1和100),下列命令中正确的是:( ) A: Dim x(9) As Integer For i = 1 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next B: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Rnd(10) Print x(i); Next C: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 ) Print x(i); Next D: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next
- 声明一个变量为局部变量应该用( )。 A: Private Sub Command1 Click() n=5:x=1 Do X=X * I I=I + 1 Loop While I < n Print x End Sub B: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X*I I=I + 1 Loop While I <n Print x End Sub C: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X * I I=I + 1 Loop While I<=n Print X End Sub D: Private Sub Command1_Click() n=5:X=1:I=1 Do X=X * I I=I + 1 Loop While I>n Print X End Sub
- 下面程序的功能是统计字符串中“i”的个数,请填空。 Sub COU( ) Dim n As Integer a$ = "Beijing University of Technology" n = Len(a$ ) For i = 1 To n b$ =Mid$(a$,i, 1) If 【11】 Then x=x + 1 Next Print "x ="; x End Sub
- 以下定义数组或给数组元素赋值的语句中,正确的是 A: Dim x%(2) x(1)="等级考试" B: Dim x(3), y(3)As Integer x(0)=1:y=x C: Dim x x=Array(0,1,2) D: Dim x(3)As Integer x=Array(0,1,2)