vb代码编程实例(vb代码)
来源:     时间:2023-07-11 01:03:50


【资料图】

1、Option ExplicitFunction fc(a) As BooleanDim i As LongFor i = 2 To Int(a / 2)If a Mod i = 0 Thenfc = FalseExit ForElsefc = TrueEnd IfNext iEnd FunctionPrivate Sub Form_Click()Dim i, j, k, m, s, g, f As Integerj = 0k = 0f = 0Dim a(1 To 80) As IntegerDim b(1 To 80) As IntegerDim c(1 To 80) As IntegerDim d(1 To 80) As IntegerFor i = 1 To 80a(i) = Int(Rnd() * 100)if a(i)<10 then a(i)=a(i)+10If a(i) Mod 2 = 0 Thenj = j + 1b(j) = a(i)Elsek = k + 1c(k) = a(i)End IfNext iFor i = 1 To jFor m = i + 1 To jIf b(i) < b(m) Thens = b(m)b(m) = b(i)b(i) = sEnd IfNext mNext iFor i = 1 To kFor m = i + 1 To kIf b(i) < b(m) Thens = c(m)c(m) = c(i)c(i) = sEnd IfNext mNext iFor i = 1 To 80If fc(a(i)) = True Theng = g + 1d(g) = a(i)End IfNext iPrint "随机数:"For i = 1 To 80f = f + 1If f < 11 ThenPrint " " & a(i);Elsef = 1PrintPrint " " & a(i);End IfNext iPrintPrint "偶数:"f = 0For i = 1 To jf = f + 1If f < 11 ThenPrint " " & b(i);Elsef = 1PrintPrint " " & b(i);End IfNext iPrintPrint "奇数:"f = 0For i = 1 To kf = f + 1If f < 11 ThenPrint " " & c(i);Elsef = 1PrintPrint " " & c(i);End IfNext iPrintPrint "素数:"f = 0For i = 1 To gf = f + 1If f < 11 ThenPrint " " & d(i);Elsef = 1PrintPrint " " & d(i);End IfNext is = 0PrintPrint "素数个数:" & gFor i = 1 To gs = s + d(i)Next iPrint "素数总和:" & sEnd Sub。

本文就为大家分享到这里,希望小伙伴们会喜欢。

关键词:

新闻推荐