'只有一个按钮,窗体大一些(尤其是窗体高度)'本代码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'---------------------------'程序结束,
求高手作一vb程序(二)内容利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇
1个回答
相关问题
-
随机产生20个10~99的正整数,除去其中的偶数,再将剩余的奇数从大到小排列 用vb编写
-
vb程序考试。在线等写程序。1、(1)用随机函数产生10个两位数的整数,将这10个数存入数组;(2)按从大到小的顺序将这
-
1、随机产生10个10-99范围内的整数,分别用选择和冒泡法将数据按从大到小递减的顺序排列,并显示排序结果
-
VB随机产生30个[10,99]的自然数.
-
VB怎么写随机生成10个[1,100]之间的数,并从大到小排列的程序?
-
VB语句填写设计VB程序,使其具有下列功能:单击“计算”按钮Command1,随机产生10个[10,99]区间内的整数,
-
vb语言中利用随机函数产生20个50~100之间的随机整数,显示他们的最大值,最小值和
-
(1)VB 用随机函数产生20个两位数的整数,存于4行5列的二维数组中,并求出其中的最大元素及它的行、列坐标,将数组按行
-
VB:随机产生30个[100,500]区间的随机整数,求其和及平均值.
-
vb问题 高手请进随机产生50个整数(范围20..50),求之中能被3整除的最小数并与数组中的第一个元素交换位置,输出交