求高手作一vb程序(二)内容利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇

1个回答

  • '只有一个按钮,窗体大一些(尤其是窗体高度)'本代码80个随机数按不可重复处理,按可重复处理的代码见后面Option ExplicitDim i, j, k, m, n, u, v, wDim s(80)Dim cf As BooleanDim mm As SingleDim nn As BooleanDim cc As SingleDim js(100) As SingleDim os(100) As SingleDim flag As BooleanDim yy As SingleDim sss As SingleDim Sum As SingleDim fu As SingleDim fv As SinglePrivate Sub Command1_Click()i = 1Do While i <= 80cf = FalseRandomizek = Int(Rnd() * 90) + 10For j = 1 To iIf k = s(j) Thencf = TrueExit ForEnd IfNextIf cf = False Thens(i) = ki = i + 1End IfLoopPrint "80个随机数:"i = 1u = 1v = 1For m = 1 To 8For n = 1 To 10If s(i) Mod 2 = 0 Thenos(u) = s(i)u = u + 1Elsejs(v) = s(i)v = v + 1End IfPrint s(i);i = i + 1Next nPrint:Next m Dim uu(0 To 80) As Single, p%, q%, tDim vv(0 To 80) As SingleFor w = 1 To u - 1vv(w) = os(w)Next wFor p = 1 To u - 1 - 1For q = u - 1 To p + 1 Step -1If vv(q) < vv(q - 1) Thent = vv(q) vv(q) = vv(q - 1)vv(q - 1) = tEnd IfNext qNext pPrint "偶数排序后:"w = 1If m Mod 10 = 0 Thenfu = 1Elsefu = 0End IfFor m = 1 To (u - 1) 10 + 1 - fuFor n = 1 To 10If vv(w) = 0 ThenElsePrint vv(w);End Ifw = w + 1Next nPrint:Next mFor w = 1 To v - 1uu(w) = js(w)Next wFor p = 1 To v - 1 - 1For q = v - 1 To p + 1 Step -1If uu(q) > uu(q - 1) Thent = uu(q) uu(q) = uu(q - 1)uu(q - 1) = tEnd IfNext qNext pPrint "奇数排序后:"w = 1If m Mod 10 = 0 Thenfv = 1Elsefv = 0End IfFor m = 1 To (v - 1) 10 + 1 - fvFor n = 1 To 10If uu(w) = 0 ThenElsePrint uu(w);End Ifw = w + 1Next nPrint:Next mPrint "素数:"w = 1mm = 1sss = 0For yy = 1 To 80cc = s(yy)nn = sushu(cc)If nn = False ThenPrint s(yy);sss = sss + 1Sum = Sum + ccIf sss Mod 10 = 0 ThenIf sss = 0 ThenElsePrint:End IfEnd IfEnd IfNext yyPrint:Print "素数总数:";Print sss:Print "素数总和:";Print SumEnd SubPrivate Function sushu(g As Single) As BooleanDim h As SingleDim flag As Booleanflag = FalseFor h = 2 To Sqr(g)If g Mod h = 0 Thenflag = TrueExit ForEnd IfNext hsushu = flagEnd Function'---------------------------'程序结束,'以下为80个随机数按可重复处理的代码'只有一个按钮,窗体大一些(尤其是窗体高度)'本代码80个随机数按可重复处理,Option ExplicitDim i, j, k, m, n, u, v, wDim s(80)Dim cf As BooleanDim mm As SingleDim nn As BooleanDim cc As SingleDim js(100) As SingleDim os(100) As SingleDim flag As BooleanDim yy As SingleDim sss As SingleDim Sum As SingleDim fu As SingleDim fv As SinglePrivate Sub Command1_Click()i = 1Do While i <= 80Randomizek = Int(Rnd() * 90) + 10s(i) = ki = i + 1LoopPrint "80个随机数:"i = 1u = 1v = 1For m = 1 To 8For n = 1 To 10If s(i) Mod 2 = 0 Thenos(u) = s(i)u = u + 1Elsejs(v) = s(i)v = v + 1End IfPrint s(i);i = i + 1Next nPrint:Next m Dim uu(0 To 80) As Single, p%, q%, tDim vv(0 To 80) As SingleFor w = 1 To u - 1vv(w) = os(w)Next wFor p = 1 To u - 1 - 1For q = u - 1 To p + 1 Step -1If vv(q) < vv(q - 1) Thent = vv(q) vv(q) = vv(q - 1)vv(q - 1) = tEnd IfNext qNext pPrint "偶数排序后:"w = 1If m Mod 10 = 0 Thenfu = 1Elsefu = 0End IfFor m = 1 To (u - 1) 10 + 1 - fuFor n = 1 To 10If vv(w) = 0 ThenElsePrint vv(w);End Ifw = w + 1Next nPrint:Next mFor w = 1 To v - 1uu(w) = js(w)Next wFor p = 1 To v - 1 - 1For q = v - 1 To p + 1 Step -1If uu(q) > uu(q - 1) Thent = uu(q) uu(q) = uu(q - 1)uu(q - 1) = tEnd IfNext qNext pPrint "奇数排序后:"w = 1If m Mod 10 = 0 Thenfv = 1Elsefv = 0End IfFor m = 1 To (v - 1) 10 + 1 - fvFor n = 1 To 10If uu(w) = 0 ThenElsePrint uu(w);End Ifw = w + 1Next nPrint:Next mPrint "素数:"w = 1mm = 1sss = 0For yy = 1 To 80cc = s(yy)nn = sushu(cc)If nn = False ThenPrint s(yy);sss = sss + 1Sum = Sum + ccIf sss Mod 10 = 0 ThenIf sss = 0 ThenElsePrint:End IfEnd IfEnd IfNext yyPrint:Print "素数总数:";Print sss:Print "素数总和:";Print SumEnd SubPrivate Function sushu(g As Single) As BooleanDim h As SingleDim flag As Booleanflag = FalseFor h = 2 To Sqr(g)If g Mod h = 0 Thenflag = TrueExit ForEnd IfNext hsushu = flagEnd Function'---------------------------'程序结束,