我们VB老师留的专业作业(已开源)
开源地址
cui/shujia-vb-homkwork - 码云 - 开源中国 (gitee.com)
本作业我将使用VB6.0进行编写
思路
1,随机产生10个两位数数字我们可以用rnd进行计算,使用“上限减下限+1取整的值+下限的万能公式进行编写”
2,逆序的方式我可以使用三种方法字符法,循环对角调换法,折半调换法
3,4,我就直接用冒泡排序法就即刻找出最大值和最小值
代码展示
随机产生数
Dim Num1%
Dim S$
Randomize
A(1) = Int(Rnd * (99 - 10 + 1) + 10)
For I = 2 To 10
Num1 = Int(Rnd * (99 - 10 + 1) + 10)
A(I) = Num1
Next I
For I = 1 To 10
S = S + Str(A(I))
Next I
Label1.Caption = S
MsgBox S, vbOKOnly, ""
逆序输出
Sub N1()
Dim S$
For I = 10 To 1 Step -1
S = S + Str(A(I))
Next I
MsgBox S, vbOKOnly, ""
End Sub
Sub N2()
Dim S$, B%(10)
For J = 1 To 10
B(11 - J) = A(J)
Next J
For I = 1 To 10 Step 1
S = S + Str(B(I))
Next I
MsgBox S, vbOKOnly, ""
End Sub
Sub N3()
Dim S$, B%(10)
For J = 1 To 10
B(J) = A(J)
Next J
For J = 1 To 5
B(J) = B(J) + B(11 - J)
B(11 - J) = B(J) - B(11 - J)
B(J) = B(J) - B(11 - J)
Next J
For J = 1 To 10 Step 1
S = S + Str(B(J))
Next J
MsgBox S, vbOKOnly, ""
End Sub
第三块
Sub P1()
Dim S$
S = ""
Dim F As Boolean
For N = 1 To 9
F = False
For M = 1 To 10 - N
If C(M) > C(M + 1) Then
C(M) = C(M) + C(M + 1)
C(M + 1) = C(M) - C(M + 1)
C(M) = C(M) - C(M + 1)
End If
Next
Next N
For N = 1 To 10
If A(N) = C(1) Then
S = S & "最小值位置" & N & "值为" & CStr(C(1)) & ","
A(N) = 0
End If
If A(N) = C(10) Then
S = S & "最大值位置" & N & "值为" & CStr(C(10))
A(N) = 0
End If
Next N
MsgBox S
End Sub
效果展示
源码下载
本文是原创文章完整转载请注明来自 逐月星屿
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果