vb编程 输入一个数看看是不是质数,要用IsPrime这个方程Prime NumbersA prime number is a number that can be evenly divided by only itself and 1.Forexample,the number 5 is prime because it can be evenly divided by only 1 and 5.Thenumber
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 08:55:28
vb编程 输入一个数看看是不是质数,要用IsPrime这个方程Prime NumbersA prime number is a number that can be evenly divided by only itself and 1.Forexample,the number 5 is prime because it can be evenly divided by only 1 and 5.Thenumber
vb编程 输入一个数看看是不是质数,要用IsPrime这个方程
Prime Numbers
A prime number is a number that can be evenly divided by only itself and 1.For
example,the number 5 is prime because it can be evenly divided by only 1 and 5.The
number 6,however,is not prime because it can be evenly divided by 1,2,3,and 6.
Write a Boolean function named IsPrime which takes an integer as an argument
and returns true if the argument is a prime number or false otherwise.Use the func-
tion in an application that lets the user enter a number and then displays a message
indicating whether the number is prime.
vb编程 输入一个数看看是不是质数,要用IsPrime这个方程Prime NumbersA prime number is a number that can be evenly divided by only itself and 1.Forexample,the number 5 is prime because it can be evenly divided by only 1 and 5.Thenumber
Private Function isPrime(intIndicated As Integer) As Boolean
If intIndicated >= 2 Then
isPrime = True
For i = 2 To intIndicated - 1
If intIndicated Mod i = 0 Then isPrime = False: Exit For
Next i
Else
isPrime = False
End If
End Function
Private Sub Command1_Click()
Dim intInput As Integer
intInput = InputBox("Please enter a integer :", "Enter a number")
If isPrime(intInput) Then
MsgBox intInput & " is a prime number."
Else
MsgBox intInput & " is NOT a prime number."
End If
End Sub
另外,你用的是VB6还是.NET,我上面是按VB6写的.