vb.net计算数的因子 vb求质因子的算法

vb 对给定的正整数 , 求因子,对每个因子判断是否为质数,将所有的质数因子放入动态组中,最后输出动态组Option Explicit
Private Sub Command1_Click()
Dim n As Integer
Dim d() As Integer
Dim k As Integer
Dim i As Integer
Dim m As Integer
k = 0
n = Val(InputBox("输入任意自然数vb.net计算数的因子!"))
'先求因数
Print "因数vb.net计算数的因子:";
m = n
For i = 1 To n
If m Mod i = 0 Then
Print i; ",";
End If
Next i
Print
Print
'再求质因数
Print "质因数vb.net计算数的因子:";
m = n
【vb.net计算数的因子 vb求质因子的算法】i = 1
Do While m1
i = i1
Do While m Mod i = 0
k = k1
ReDim Preserve d(k) As Integer
d(k) = i
m = m \ i
Loop
Loop
For i = 1 To UBound(d)
Print d(i); ",";
Next i
Print
End Sub
vb小白请教一个求因子数的问题(输入一个整数,显示不同因子和因子个数)m是函数vb.net计算数的因子的形参vb.net计算数的因子,就是参数,在调用vb.net计算数的因子的时候传进去个啥数不知道,用它代替
fun(n)的n就是实参,就是具体传进去的数,传进去后m的数值就是nvb.net计算数的因子了
For k = 1 To Abs(m) / 2,如果这个不是整数----那需要处理一下,比如用int函数
fun带参数并且作为返回的数值的时候fun要带上()
fun带参数并且不作为返回的数值的时候fun不要带上(),fun后面是空格和参数
没有参数的时候直接写
vb 中求数的因子 。数字通过Inputbox函数输入,点击按钮后在文本框中输出相应的因子 。如6的因子是1、2、3 。Private Sub Command1_Click()
Dim n As Integer, i As Integer
n = InputBox("输入正整数:", , 0)
If n0 Then
Text1.Text = Empty
For i = 1 To n - 1
If n Mod i = 0 Then
Text1.Text = Text1.Texti","
End If
Next
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
VB问题:输入一个正整数,求出它的所有质因子,并按乘积形式打印如:28=2*2*7请高手帮忙谢谢~!Private Sub Form_Click()
Dim n As Integer
n = InputBox("输入一个整数")
Print n"="Join(GetFactorArray(n), "*")
End Sub
Public Function GetFactorArray(ByVal n As Long)
'返回质因子的乘积
Dim arr()
Dim m As Long
For i = 2 To n / 2
Do While n1
If n Mod i = 0 Then
ReDim Preserve arr(m)
arr(m) = i
m = m1
n = n / i
Else
Exit Do
End If
Loop
Next i
If m0 Then
GetFactorArray = arr
Else
GetFactorArray = Array(n)
End If
End Function
“输入任意正整数,输出该数的所有因子及因子个数”在vb中怎么编程dim number as integer'输入的正整数
dim yz as integer'因子
dim num as integer'因子个数
dim i as integer'循环变量
num = 0
print number"的因子有:"
for i=1 to numner/2
if (number\i)*i=number then
num = num1
printf i
endif
next i
print "共计" num "个因子"
VB求整数因子的个数以及和Dim i As Integer
Dim a As Integer
Dim sum As Integer
Dim s As String
Dim j As Integer
a = InputBox("请输入一个数")
For i = 1 To a
If a Mod i = 0 Then
If s"" Then s = s","
s = si
sum = sumi
j = j1
End If
Next i
Print "该数的整数因子:"s
Print "因数个数:"j
Print "因数和:"sum
vb.net计算数的因子的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vb求质因子的算法、vb.net计算数的因子的信息别忘了在本站进行查找喔 。

    推荐阅读