将其中的偶数按由小到大的顺序排列,将奇数按由大到小的顺序排列;在产生的90个随机整数中,找出其中的素数,并将这些素数求和。
将找出的素数按每行20个数在文本框中输出,将素数的个数及求和结果也输出到同一个文本框中。
Private Sub Command1_Click()
Dim a(90) As Integer, i As Integer, ii As Integer, j As Integer, s As Integer, ss As Integer, he As Integer
Print "随机生成数:"
For i = 1 To 90
a(i) = Int(Rnd * 90 + 10)
Print a(i);
If i Mod 18 = 0 Then Print
Next i
For i = 1 To 89
For ii = i To 90
If a(i) > a(ii) Then
j = a(i)
a(i) = a(ii)
a(ii) = j
End If
Next ii
Next i
Print
Print "偶数(由小到大排列):"
For i = 1 To 90
If a(i) Mod 2 = 0 Then
Print a(i);
s = s + 1
If s Mod 18 = 0 Then Print
End If
Next i
s = 0
Print: Print
Print "奇数(由大到小排列):"
For i = 90 To 1 Step -1
If a(i) Mod 2 <> 0 Then
Print a(i);
s = s + 1
If s Mod 18 = 0 Then Print
End If
Next i
s = 0
Print: Print
Print "其中的素数有:"
For i = 1 To 90
ss = 0
For ii = 2 To a(i) - 1
If a(i) Mod ii = 0 Then ss = ss + 1
Next ii
If ss = 0 Then
Print a(i);
he = he + a(i)
s = s + 1
If s Mod 18 = 0 Then Print
End If
Next i
Print: Print
Print "素数和为:" & he
End Sub
Private Sub Command2_Click()
Form1.Cls
End Sub
利用随机函数产生80个10~99之间的随机整数,
4个文本框,一个命令按钮,文本框MultiLine属性都设置成True Option Base 1 Private Function sushu(x As Integer) As Boolean Dim i As Integer For i = 2 To x - 1 If x Mod i = 0 Then Exit Function Next i sushu = True End Function Private Sub Command1_Click()Dim i As Intege...
...编写程序通过随机函数产生10~99之间的随机整数?
vb 产生随机数的公式(上界-下界+1)*rnd+下界你的题目就应该是(99-10+1)*rnd +10一般用rnd的时候还要在前面加一条 randomize 初始化随机种 子
关于VB随机函数的问题,急急急!!
[10,99]之间的随机数:int((99-10+1)*rnd+10) 也就是:int(90*rnd+10).这样理解:由于rnd的取值范围是[0,1) 所以当rnd为0时,结果=int(90*0+10)=int(10)=10;当rnd为0.9999时,结果 int(90*0.9999+10)=int(89.9999+10)=int(99.9999)=99 ...
产生随机数 vb
Dim a(1 To 80) As Integer Dim er(1 To 80) As Integer Dim ji(1 To 80) As Integer Dim k, n, i As Integer n = 0 k = 0 For i = 1 To 80 a(i) = Int((99 - 10 + 1) * Rnd + 10) ' 生成 10 到 99 之间的随机数值。If a(i) Mod 2 = 0 Then '如果是...
用随机函数产生10-99.99之间任意的两位整数 Free Pascal IDE_百度知 ...
这道题目简单来说,就是求10~99之间的随机整数,程序如下:var i,n:longint;begin readln(n);{输入你要的随机数的个数} randomize;{初始化随机数发生种子} for i:=1 to n do writeln(random(89)+11);{输出10~99之间的随机整数} end....
利用随机函数产生100个10~99之间的随机整数,找出其中的素数,并将这...
Print "随机数" & i & "数值" & lngTemp & " " & IIf(checkNum(lngTemp), "", "不") & "是素数"Next Print "素数和为:" & lngSum End Sub Function checkNum(ByVal lngNum As Long) As Boolean Dim blnRet As Boolean blnRet = True For i = 2 To Sqr(lngNum)I...
vb编写一个程序,利用随机函数Rnd生成10个10-99之间的整数,并计算其中素...
n= [ 10+int(90*rnd) ]st = [ st + " " + n ]forj=2 to [ n ][ n1=n1+1 ][ exit for ]text1.text=[ st ]text2.text= [ n-n1 ]
vb随机数问题
Print "素数个数是:" & c Print "素数的和是:" & d End FunctionPrivate Sub Command1_Click()Cls Print "产生80个10~99之间的随机整数是:"Randomize For b = 1 To 80 '随机函数产生80个10~99之间的随机整数 a(b) = Int((Rnd * 90) + 10)Print a(b);If b Mod 10 = 0 ...
用vb编程实现随机产生一个100到999之间的随机数,并将此数逆序输出_百度...
VBA编程实现不重复随机数输出。VBA里的随机函数是RND,在工作表中随机函数是RAND,一字之差,可要记好了。RND取值范围是[0,1),意思是0和1之间的一个随机数,包含0,但不包含1。1、用法 语法:Rnd[(number)]如果 number 的值是 Randomize 生成小于 0 ,每次都使用 number 作为随机数种子得到的...
vb编写程序利用随机函数rnd生成十个10-99之间的整数并分别求出偶数与...
i奇数 = 0 Dim i偶数 As Integer i偶数 = 0 Dim allNumber As String Dim iTemp As Integer For i = 1 To 10 iTemp = Rnd * 90 + 10 If i > 1 Then allNumber = allNumber & ","End If allNumber = allNumber & iTemp If iTemp Mod 2 = 0 Then i偶数 = i偶数 + 1 Else...