1樓:風華正茂
dim n as long
dim s as double
n=inputbox("請輸入n的值:")s=1 's初值設為1for i=1 to n step 1
s= s * i
next i
print s '最後輸出
2樓:匿名使用者
dim n as long
dim i as long
dim s as long
n = 6
s = 1
for i = 1 to n
s = s * i
next
debug.print(s)
樓上的那個在n=0 的時候結果不對
3樓:匿名使用者
public function fjc(byval n as integer) as long
dim jc as long
if n < 0 then
jc = -1 '表示負數沒有階乘elseif n = 0 then
jc = 1 '0的階乘=1elseif n > 0 then
on error goto errhandeljc = 1
for i = 1 to n
jc = jc * i
next
end if
fjc = jc
exit function
errhandel: fjc = -2 '表示資料過大,造成溢位
end function
4樓:大宇世界
dim n as integer
dim i as integer
n = 5
for i = n - 1 to 1 step -1n = n * i
next
試一下吧,是for迴圈不會用吧~
vb程式設計。輸入整數n,計算1!+2!+3!….+n!的值,並在窗體上輸出。要求分別用for,while 兩種迴圈實現
5樓:落葉l無情
dim i as integer, j as integerdim n as integer, sum as long, jc as long
n = inputbox("請輸入:") '如果是用文字框text1輸入,這裡改為 n=val(text1)
sum = 0
for i = 1 to n
jc = 1
for j=1 to i
jc = jc * j
next j
sum = sum + jc
next i
print sum
while:
dim i as integer, j as integerdim n as integer, sum as long, jc as long
n = inputbox("請輸入:")
sum = 0
i = 1
while i <= n
jc = 1
j = 1
while j <= i
jc = jc * j
j = j + 1
wend
sum = sum + jc
i = i + 1
wend
print sum
c 中怎麼用迴圈語句算2的n次方
哈哈,這個簡單,我寫個 給你。1.include void main cout 1 2 3 20 void main cout 1 1 1 2 1 3 1 50 你的串號我已經記下,採納後我會幫你製作 樓上的好像有有問題啊!我試了一下結果 e 未宣告的識別符號我改了一下,就是下面的 include ...
vb中ubound怎麼用,Ubound 在VB中怎麼用啊?!
ubound函式返回陣列的最大下標 dim s 4 as string dim i as integer i 4 i ubound s 就是取陣列的最大下標。格式 ubound 陣列,第幾維 給一段 執行一下 新建一窗體,然後到 區,刪除所有 後,貼上以下 可見執行效果 option explici...
vb程式設計用for迴圈向一維陣列中輸入數找出其中
題目不是交代了要用迴圈,但是你沒用啊,沒用迴圈是做不了這件事的。dim x 1 to 10 as integer,max as integer,min as integer,i as integer label1.caption for i 1 to 10 x i val inputbox 輸入第 ...