实验内容 利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇数按

Private Sub Command1_Click()
Dim s1, s2 As String
Randomize
Dim a(80) As Integer
For i = 1 To 80
a(i) = 10 + Int(Rnd * 90)
Next i
For i = 1 To 80
Print a(i);
If i Mod 10 = 0 Then
Print
End If
Next
For i = 1 To 79
For j = i + 1 To 80
If a(i) > a(j) Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i

n = 0
For i = 1 To 80
If a(i) Mod 2 = 0 Then
s1 = s1 + Str(a(i))
n = n + 1
If n Mod 10 = 0 Then s1 = s1 + Chr$(13) + Chr$(10)
End If
Next i
Print s1

n = 0
For i = 80 To 1 Step -1
If a(i) Mod 2 <> 0 Then
s2 = s2 + Str(a(i))
n = n + 1
If n Mod 10 = 0 Then s2 = s2 + Chr$(13) + Chr$(10)
End If
Next i
Print s2
Print
For i = 1 To 80
fnprime (a(i))
Next

End Sub
Function fnprime(m As Integer) As Boolean
Dim k As Integer, f As Boolean
f = True
For k = 2 To m - 1
If m Mod k = 0 Then
f = False
End If
Next k
If f = True Then
Print m;
End If

End Function
我已经做到这了,请帮忙把素数每行10个输出,然后再输出素数的个数,急求呀
我要的是VB语言编程,不是C或C++

第1个回答  2011-06-13
Dim a%(1 to 80), i%, k%, t%, b%(1 to 80), c%(1 to 80)
Private Sub Command1_Click()
Me.Cls
Dim j As Integer
Randomize
t = 1
k = 1
For i = 1 To 80
a(i) = Int(Rnd * 90) + 10

If a(i) Mod 2 = 1 Then
b(k) = a(i)
k = k + 1
End If

If IsPrimeNum(a(i)) Then
c(t) = a(i)
t = t + 1
End If
Next i

Print "全部"

For i = 1 To 80
Print a(i);
If i Mod 10 = 0 Then Print
Next i

SortArray b, k - 1

Print "奇数"

For i = 1 To k - 1
Print b(i);
If i Mod 10 = 0 Then Print
Next i

Print

SortArray c, t - 1

Print "素数"

For i = 1 To t - 1
Print c(i);
If i Mod 10 = 0 Then Print
Next i
End Sub

Private Function IsPrimeNum(V As Integer) As Boolean
Dim i As Integer
Dim flag As Boolean
flag = True
For i = 2 To V - 1
If V Mod i = 0 Then
flag = False
Exit For
End If
Next i
IsPrimeNum = flag

End Function

Private Sub SortArray(arr() As Integer, ByVal size As Integer)
Dim i As Integer
Dim j As Integer
Dim t As Integer
For i = 1 To size
For j = i + 1 To size
If arr(i) > arr(j) Then t = arr(i): arr(i) = arr(j): arr(j) = t
Next j
Next i

End Sub追问

这个程序最后素数还是没有求和啊,跪求素数求和代码

第2个回答  2011-06-12
Next k
If f = True Then
Print m;
End If
这里修

Dim j
If f = True Then
j=j+1;
if(j%10 == 0) Then
Print 回车(我也不知道vb的回车怎么输出,你自己加上去看看吧)
End If
Print m;
End If
Print j;

实验内容 利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由...
Dim a%(1 to 80), i%, k%, t%, b%(1 to 80), c%(1 to 80)Private Sub Command1_Click()Me.Cls Dim j As Integer Randomize t = 1 k = 1 For i = 1 To 80 a(i) = Int(Rnd * 90) + 10 If a(i) Mod 2 = 1 Then b(k) = a(i)k = k + 1 End If If ...

利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小到大的...
for(i=1;i<=80;i++){a[i]=randon(10,99);} for(i=1;i<=80;i++){ if a[i]%2==0{ b[0]=0;循环比较存入b[m]else 同上 }

利用随机函数产生80个10~99之间的随机整数,将其中的奇数按由小到大的...
邮件已发送

利用随机函数产生80个10~99之间的随机整数,
Private Sub Command1_Click()Dim i As Integer, a(80) As Integer, j As Integer, b(80) As Integer, n As Integer, t As Integer, k As Integer Dim c(80) As Integer, m As Integer For i = 1 To 80 a(i) = Int(Rnd * 90 + 10)Next i For i = 1 To 80 Text1.Text...

随机产生80个10~99的随机整数将其中的奇数由小到大的排列并输出产生的...
1.将随机产生的80个整数存入数组,按每行10个数输出到窗体或文本框中。2.奇数也存入另一个数组,将排好序的奇数输出到窗体或文本框中。3.用Sub子过程或Function函数过程判断随机整数是否为素数。4.将素数按每行10个数在窗体或文本框中输出。提问者: 付木仁 - 一级 ...

vb随机数问题
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 Then Print End If Next '偶数由小到大 For b = 1 To 80 For c = b To 80 If a(c) > a(b ...

求80个10到99之间的数打印在文本框后求奇数求素数每行10个输出素数用...
如果你是需要C\/C++的源码我倒可以写个,但是算法应该大同小异

利用随机函数产生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...

...10个10~99之间的随机整数,再按升序输出这10个数。
而有效!!Private Sub Command1_Click()Cls Dim a(10) As Integer Dim b As Integer For i = 1 To 10 a(i) = Int(Rnd * 90 + 10)For j = 1 To i If a(j) > a(i) Then b = a(j)a(j) = a(i)a(i) = b End If Next j Print a(i)Next i End Sub ...

作业: 随机产生20个10~99之间的整数,要求: 1) 用冒泡法排序(降序) 2...
x=val(inputbox("请输入一个整数"))redim a%(x)for i= 1 to x a(i)=int (rnd*90+10)next i for i= 1 to x for j=i+1 to x-i if a(j)

相似回答