VB程序 求出100-200之间的所有质数
Private Function prime(n As Integer) As Boolean '返回值=True是素数,False不是素数 Dim k As Integer prime = True For k = 2 To n - 1 If (n Mod k) = 0 Then prime = False: Exit For Next k End Function Private Sub Command1_Click()Dim i As Integer, j As Integer Fo...
求出100-200之间的所有素数的VB程序设计。
以下是求出100-200之间的所有素数的VB程序设计:Public Function IsPrime(ByVal num As Integer) As Boolean ' 判断一个整数是否为素数 If num < 2 Then IsPrime = False ElseIf num = 2 Then IsPrime = True ElseIf num Mod 2 = 0 Then IsPrime = False Else Dim i As Integer For i =...
100到200之间的质数,急!!! 谢谢了,
Vb利用判素数函数,完成100到200之间所有素数平均值的输出。急急急!!!Function PrimeAvg() As Double Dim sum As Integer Dim count As Integer Dim i As Integer sum = 0 count = 0 For i = 100 To 200 If IsPrime(i) Then sum = sum + i count = count + 1 End If Next PrimeA...
求100以内的所有质数(素数) 要求:用VB的for语句写
For n = 2 To 100 '2到100循环 For i = 2 To Int(Sqr(n)) 'sqrt(n)求开方用int取整 If n Mod i = 0 Then Exit For '如果2到100中的有数字满足不能被2到该数字开方的自然数除尽,它就是你要的素数!Next i If i > Int(Sqr(n)) Then '从2到int(sqrt(n))没有找到可以除尽...
vb中怎么输出1到100之间的所有质数?
你的题目有些问题,应该是2到100之间,应为质数应该是从2开始的用FOR做就行了,只要mod 2 ,3,5,7得到的都是0,就是质数了
vb编程求1-100内的质数
我给你个程序,可以求出任意正整数M到正整数N之间的所有质数。(N-M>50)先创建两个文本框,一个命令按钮,一个图片框,代码如下:Private Sub Command1_Click()Dim m, n, i, s, t As Integer m = Val(Text1)n = Val(Text2)For i = m To n s = 1 Do s = s + 1 Loop While...
VB语言中,输出100以内的自然数中的所有质数,且每5个数字一行。求完整代...
程序如下:Private Sub Form_Click()Dim I As Integer,J As Integer Dim Y As Boolean Dim K As Integer K=0 For I=2 To 100 Y=True For J=2 To Sqr(I)If I Mod J=0 Then Y=False Exit For EndIf Next J If Y Then Print I;K=K+1 If K Mod 5=0 Then Print EndIf Next ...
如何用VB设计程序找出100以内的质数?
Private Sub Command1_Click()For i = 2 To 100 For j = 2 To Sqr(i)If i Mod j = 0 Then Exit For Next If j > Sqr(i) Then Print i Next End Sub
使用VB编程解决以下问题 1.编程计算200以内所有质数的和
Private Sub Command1_Click()Dim sum As Long sum = 0 For i = 2 To 200 For j = 2 To i If i Mod j = 0 Then Exit For Next j If j = i Then sum = sum + i Next i MsgBox "质数和为:" & sum End Sub
新概念VB中100内所有质数两种方法
Private Sub Form_Load()Show '第一种方法,因为1既不是素数也不是合数,所以不能放在里 Dim s%(1 To 99), f As Boolean, k For i = 2 To 100 f = False For j = 2 To Sqr(i)If i Mod j = 0 Then f = True: Exit For Next j If Not f Then If k Mod 10 = 0 Then ...