vb编程 输入一个数看看是不是质数,要用IsPrime这个方程
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/13 15:00:29
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.
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.
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写的.
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写的.
编写一个函数名为isprime(),判断一个数是不是素数(即质数).在主函数中输入一个整数,然后调用子函数isprime
VB编程:输入一个数,求这个数与其倒数之和
VB编程:输入一个数,求它的自然数对,
java编程实现:从键盘任意输入一个数,判断这个数是不是7的倍数.
vb!输入一个四位数,求四个数字之和,判断和是不是质数
vb编程 输入一个数,随即产生一些随机数,要求产生的随机数的平均值等于输入的数
任意输入一个自整数,判断是不是质数(用C语言编程)
用vb编程:输入三个数,求出最大的数
VB编程,如果一个三位整数等于其各位数字的立方和,则称这个数为水仙花数.输入一个整数判断其是否为水仙花数.
在vb中 ,输入一个正整数,编程判断该数是奇数还是偶数. Private Sub Form_Click() Dim X
C语言编程:输入一个数判断是否为素数(质数),输出判断结果信息(prime number素数).
9^n+2是不是质数vb编程如下Private Sub Command1_Click()Dim a As Integer