VB(VBA,VBS)编程,求组合数Cmn (m为下角标,n为上角标)组合数的可能的情况...
发布网友
发布时间:2024-10-24 11:15
我来回答
共1个回答
热心网友
时间:2024-11-17 16:47
x=InputBox("请输入一个数字:",,"5")
x1=x
y=InputBox("请输入一个比"&x&"小的数字:",,"3")
s=Result(x1,y)
For i=1 To y
Execute "z"&i&"=i"
Next
for i=1 to s
d=""
For j=1 To y
d = d&eval("z"&j)&" "
Next
Execute "x"&i&"=d"
Execute "z"&y&"=z"&y&"+1"
gm()
next
for i=1 to s
st=st&vbcr&eval("x"&i)&"-- "&i
next
msgbox "C("&x&","&y&")"&vbcrst&"有 "&s&" 种排列方法:"&vbcrst&st
Function Result(a,b)
sa=1:sb=1
if a<>"" and b<>"" then
for i = 1 to b
sa = sa*a
sb = sb*i
a = a-1
next
Result = sa/sb
end if
End Function
Function gm()
For q=y To 2 Step -1
If eval("z"&q)=q+x-y+1 Then
Execute "z"&q-1&"=z"&q-1&"+1"
For p=q To y
Execute "z"&p&"=z"&p-1&"+1"
next
End If
Next
End Function
热心网友
时间:2024-11-17 16:51
x=InputBox("请输入一个数字:",,"5")
x1=x
y=InputBox("请输入一个比"&x&"小的数字:",,"3")
s=Result(x1,y)
For i=1 To y
Execute "z"&i&"=i"
Next
for i=1 to s
d=""
For j=1 To y
d = d&eval("z"&j)&" "
Next
Execute "x"&i&"=d"
Execute "z"&y&"=z"&y&"+1"
gm()
next
for i=1 to s
st=st&vbcr&eval("x"&i)&"-- "&i
next
msgbox "C("&x&","&y&")"&vbcrst&"有 "&s&" 种排列方法:"&vbcrst&st
Function Result(a,b)
sa=1:sb=1
if a<>"" and b<>"" then
for i = 1 to b
sa = sa*a
sb = sb*i
a = a-1
next
Result = sa/sb
end if
End Function
Function gm()
For q=y To 2 Step -1
If eval("z"&q)=q+x-y+1 Then
Execute "z"&q-1&"=z"&q-1&"+1"
For p=q To y
Execute "z"&p&"=z"&p-1&"+1"
next
End If
Next
End Function