dfkt.net
当前位置:首页 >> vB累乘程序 >>

vB累乘程序

Private Sub Command1_Click() 'i用来记录累乘因子的初值,j用来记录累乘因子的终值,cj用来记录累乘结果 Dim n As Integer, i As Integer, j As Integer, cj As Long '赋初值 cj = 1 i = InputBox("请输入因子的初值:") j = InputBox("请输入因子的终值:") '从i到j的循环 For n = i To j cj = cj * n'自乘 Next n Print cj'输出 End Sub

Private Sub Command1_Click() Sum = 1 For i = 1 To 50 Sum = Sum * i Next i Print Sum End Sub

dim i as integer,s as longs=1for i=1 to 100s=s*inextprint s

k=1 for i = 1 to 9 s=s+i k=k*i next msgbox s & vbcrlf & k

的确是多一行 end if 不过这不是关键的,关键是你print s,你是想让程序输出到哪呢?你得有合适的位置. 比如你改成msgbox s就能在弹出框里显示了. sub leicheng() dim s, b s = 1 b = 1 do while b <= 100 姬鸡灌课弑酒鬼旬邯莫 s = s * b b = b + 1 loop msgbox s end sub

s=1for i= 1 to 10s=s * inextmsgbox s

Function getn(n As Integer) Dim i As Integer For i = 1 To n getn = getn + getm(i) Next i End Function Function getm(m As Integer) Dim i As Integer For i = 1 To m getm = getm + i Next i End Function Sub aa() MsgBox getn(2) End Sub

Private Sub Command1_Click()'Dim a(1 To 100)RandomizeFor i = 1 To 100 a(i) = Int(Rnd * 101)Next iFor i = 1 To 99 For j = 100 To i + 1 Step -1 If a(i) < a(j) Then b = a(i): a(i) = a(j): a(j) = bNext j, iFor i = 1 To 100 Print a(i), If i Mod 10 = 0 Then PrintNext iEnd Sub

你说的累乘,可以理解为阶乘吧?如果是180的阶乘,那么它实在太大了,VB中没有一种数据类型能够装得下它.我试了一下,VB中的double类型数据,最大可以表示170的阶乘,但是要表示171的阶乘,就会出错.

举两个例子1+2+3+4++100Dim n, sumn = 100For i = 1 To nsum = sum + iNext iprint sum这里sum=50501*2*3*4*100Dim n, sumn = 100sum = 1For i = 1 To nsum = sum * iNext iPrint sum这里sum就有点大了如果不是你想要的答案的话,请把要求写详细点

网站首页 | 网站地图
All rights reserved Powered by www.dfkt.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com