VB编程:分别求出数组中取得最大值和最小值的元素个数,并在窗体上显示
展开全部
Private
Sub
Form_Click()
Form1.AutoRedraw
=
True
Dim
A()
Dim
I
As
Integer,
J
As
Integer,
N
As
Integer
Dim
MinG
As
Integer,
MaxG
As
Integer
A
=
Array(0,
0,
3,
4,
12,
11,
34,
34,
34,
34)
For
I
=
0
To
UBound(A)
-
1
For
J
=
I
To
UBound(A)
If
A(I)
>
A(J)
Then
N
=
A(I)
A(I)
=
A(J)
A(J)
=
N
End
If
Next
Next
MinG
=
1
MaxG
=
1
For
I
=
1
To
UBound(A)
-
1
If
A(I)
=
A(0)
Then
MinG
=
MinG
+
1
If
A(I)
=
A(UBound(A))
Then
MaxG
=
MaxG
+
1
Next
Print
"数组为:"
For
I
=
0
To
UBound(A())
Print
A(I);
Next
Print
Print
"其中最小的元素为:";
A(0);
",个数为:";
MinG
Print
"其中最大的元素为:";
A(UBound(A));
",个数为:";
MaxG
End
Sub
已经运行过。
Sub
Form_Click()
Form1.AutoRedraw
=
True
Dim
A()
Dim
I
As
Integer,
J
As
Integer,
N
As
Integer
Dim
MinG
As
Integer,
MaxG
As
Integer
A
=
Array(0,
0,
3,
4,
12,
11,
34,
34,
34,
34)
For
I
=
0
To
UBound(A)
-
1
For
J
=
I
To
UBound(A)
If
A(I)
>
A(J)
Then
N
=
A(I)
A(I)
=
A(J)
A(J)
=
N
End
If
Next
Next
MinG
=
1
MaxG
=
1
For
I
=
1
To
UBound(A)
-
1
If
A(I)
=
A(0)
Then
MinG
=
MinG
+
1
If
A(I)
=
A(UBound(A))
Then
MaxG
=
MaxG
+
1
Next
"数组为:"
For
I
=
0
To
UBound(A())
A(I);
Next
"其中最小的元素为:";
A(0);
",个数为:";
MinG
"其中最大的元素为:";
A(UBound(A));
",个数为:";
MaxG
End
Sub
已经运行过。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询