VB程序填空题
1.将数组下标为偶数的元素从小到大排序,其他元素不变。保存项目为“填空3-1”。PrivateSubButton1_Click(……)HandlesButton1.Cli...
1. 将数组下标为偶数的元素从小到大排序,其他元素不变。保存项目为“填空3-1”。
Private Sub Button1_Click( ……) HandlesButton1.Click
Dim a() As Integer = {90, 49, 23, 45, 11, 45, 67, 23, 68, 56}
Dim i, j, n, temp As Integer
n = UBound(a)
For i = 0 To n
Label1.Text = Label1.Text &a(i) & vbCrLf
Next i
For i = (1) To (n\ 2 - 1) * 2 (2)
For j = (3) To (4) Step2
If a(i) > a(j) Then
temp = a(i): a(i) = a(j): a(j) = temp
End If
Next j
Next i
For i = 0 To n
Label2.Text = Label2.Text &a(i) & vbCrLf
Next i
End Sub
2 计算给定的10个数中正数之和和负数之和,最后输出这两个和数的绝对值之商。保存项目为“填空3-2”。
Private Sub Button1_Click(……) HandlesButton1.Click
Dim a() As Integer = {23, -5, 23, -45, 11, 8, -3, 38, -31, 15}
Dim s1, s2, i As Integer, x As Single
s1 = 0: s2 = 0
For i = (1) To (2)
Label1.Text = Label1.Text &a(i) & vbCrLf
If (3) Then
s1 = s1 + a(i)
Else
s2 = (4)
End If
Next i
x = s1 / Math.Abs(s2)
Label2.Text = x
End Sub 展开
Private Sub Button1_Click( ……) HandlesButton1.Click
Dim a() As Integer = {90, 49, 23, 45, 11, 45, 67, 23, 68, 56}
Dim i, j, n, temp As Integer
n = UBound(a)
For i = 0 To n
Label1.Text = Label1.Text &a(i) & vbCrLf
Next i
For i = (1) To (n\ 2 - 1) * 2 (2)
For j = (3) To (4) Step2
If a(i) > a(j) Then
temp = a(i): a(i) = a(j): a(j) = temp
End If
Next j
Next i
For i = 0 To n
Label2.Text = Label2.Text &a(i) & vbCrLf
Next i
End Sub
2 计算给定的10个数中正数之和和负数之和,最后输出这两个和数的绝对值之商。保存项目为“填空3-2”。
Private Sub Button1_Click(……) HandlesButton1.Click
Dim a() As Integer = {23, -5, 23, -45, 11, 8, -3, 38, -31, 15}
Dim s1, s2, i As Integer, x As Single
s1 = 0: s2 = 0
For i = (1) To (2)
Label1.Text = Label1.Text &a(i) & vbCrLf
If (3) Then
s1 = s1 + a(i)
Else
s2 = (4)
End If
Next i
x = s1 / Math.Abs(s2)
Label2.Text = x
End Sub 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询