以下是一个能返回数组a中最大数的函数过程代码:
Function maxval(a() As Integer) As Integer
Dim max%
max = 1
For i = 2 To 10
If a(i) > a(max) Then max = i
Next i
maxval = max
End Function
PrivateSubCommand1_Click()
Dimx(1To10)AsInteger
Fori=1To10
x(i)=Int(Rnd()*100)
Printx(i);
Nexti
Print
Printmaxval(x())
EndSub
程序运行时,发现函数过程的返回值是错的需要修改,下面的修改方案中正确的是( )。
Function maxval(a() As Integer) As Integer
Dim max%
max = 1
For i = 2 To 10
If a(i) > a(max) Then max = i
Next i
maxval = max
End Function
PrivateSubCommand1_Click()
Dimx(1To10)AsInteger
Fori=1To10
x(i)=Int(Rnd()*100)
Printx(i);
Nexti
Printmaxval(x())
EndSub
程序运行时,发现函数过程的返回值是错的需要修改,下面的修改方案中正确的是( )。
举一反三
- 利用一维数组求10个数中的最大数,补充完整以下程序。 #include void main() { int i,max, a[10];//max存放最大数 for(i=0;i<10;i++) scanf("%d",&a[i]); __①___; for(i=1;i<10;i++) if(a[i]>max) ___②__; printf("max=%d ",max); }
- 使用数组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
- 写输出下面程序的运行结果_ _。 Dim a() As Integer Private Sub Command1_Click() ReDim a(1 To 5) For i = 1 To 5 a(i) = i Next i ReDim a(1 To 10) For i = 6 To 10 a(i) = 2 * i Next i For i = 1 To 10 Print a(i); Next i End Sub
- 运行下面的程序,第二行显示结果是___________。 Private Sub Form_Click() Dim A As Integer Dim i As Integer A = 5 For i = 1 To 9 Call sub1(i, A) Print i, A Next i End Sub Private Sub sub1(x As Integer, y As Integer) Static N As Integer Dim I As Integer For I = 3 To 1 Step -1 N = N + x x = x + 2 Next I y = y + N End Sub
- 【填空题】补充完成以下函数功能,返回数组a中的第n大元素的值 int fun(int a[], int s, int n) { const int MININT = -10000; int i, j, max, index; for (i = 0; i < n; ++i) { max = MININT; for (j = i; j < s; ++j) if (a[j] > __(1)___) { max = a[j]; index = j; } a[index] = a[i]; a[i] = __(2)_____; } return max; }