“求1到10的階乘之和”用vb怎麼程式設計序

時間 2021-06-25 14:52:05

1樓:匿名使用者

'先寫一個求階乘的函式

private function factorial(byval n as integer) as long

dim i as integer, l as longl = 1

for i = 1 to n

l = l * i

next

factorial = l

end function

'新增一個按鈕控制元件

private sub command1_click()dim result as long, i as integerresult = 0

for i = 1 to 10

result = result + factorial(i)next

form1.print result

end sub

'結果為4037913

2樓:匿名使用者

結果 22.2186507936508

option explicit

private function factorial(byval n as long) as double

dim i as long

dim l as double

for i = 1 to n

l = l + 1 / i

next

factorial = l

end function

private sub command1_click()dim result as double, i as longresult = 0

for i = 1 to 10

result = result + factorial(i)next

debug.print result

end sub

編寫一個vb函式過程,計算 1~10的階乘之和 ,並將執行結果輸出在窗體上

3樓:匿名使用者

參考copy**:

private sub command1_click()dim i as integer

for i = 1 to 10

sum = sum + jc(i)

next

msgbox sum

end sub

function jc(a as integer)jc = 1

for i = 1 to a

jc = jc * i

next

end function

4樓:古舟蓑笠翁

private sub command1_click()print jc(10)

end sub

private function jc(n as integer) as long

dim i as integer

jc = 1

for i = 1 to n

jc = jc * i

next i

end function

c語言 實現1到10的平方之和

方法一 使用函式。main fun int k 結果 1,4,9,100 方法二 使用巨集。define fun a a a main 分析 預處理程式將程式中帶實參的fun替換成 k k 由於c語言中,實參的求值順序是從右向左,因此程式執行結果為 第一次迴圈 k k 為 2 1第二次迴圈 k k ...

用VB求1到100奇數和出現的問題

private sub command1 click dim i as integer,s as integeri 1 s 0 while i 99 s s i i i 2 wend msgbox s 1 3 5 99 str s end sub 你應該是用i來控制迴圈,用s來求和,如果你用s i ...

用c語言怎麼寫1到5的階乘的和,c語言1階乘 3階乘 5階乘程式怎麼寫?

娛樂小八卦啊 如下 define crt secure no warnings 1 include stdio.h include stdlib.h int main int n 0 printf 請輸入一個數字 scanf d n int i 0 int ret 1 int sum 0 for i...