VB迴圈計算10以內的奇數階乘和

2021-04-17 20:03:49 字數 1137 閱讀 7525

1樓:夏永烽

private sub command1_click()dim i as integer

dim s as integer

s = 0: i = 0

do while i <= 1000

i = i + 1:

if i mod 2 = 1 then

s = s + i

end if

loop

print "計算1至1000之間的奇數之和為:"; send sub

沒有學過vb但是樓主的程式確實存在問題,這樣改回一下應該答差不多了,對於樓上說的溢位問題就要看整形數的表示範圍了。

2樓:聽不清啊

這個題目抄

不需要if語句的

。bais定義為integer會溢位的du。

private sub command1_click()dim i as integer

dim s as long

s = 0: i = 1

do while i < 1000

s = s + i: i = i + 2

loop

print "計算1至zhi1000之間的奇數之dao和為:"; send sub

vb用函式過程1到9中奇數階乘的和

3樓:兄弟連教育北京總校

private sub command1_click()dim n,i,a,b

n = 100 '假設是100之內的數

for i = 1 to n - 1

if i mod 2 = 1 then

a = a + fc(i)

else

b = b + fc(i)

end if

next

print n & "之內奇數內階乘之

容和=" & a & vbnewline & n & "之內偶數階乘之和=" & b

end sub

function fc(n)

dim i

fc = 1

for i = 1 to n

fc = fc * i

next

end function

vb題 程式設計計算100以內素數的和

private sub command1 click dim i as integer,j as integer,k as integer for i 2 to 100 for j 2 to i if i mod j 0 then exit for end if next if i j then k...

VB 10以內加法程式,用VB設計一個簡單的加法,和求和的小程式怎麼弄

private sub form load dim i,s as integer for i 1 to 10 s s i next i print s end sub dim i as integer dim sum as integer for i 1 to 10 sum sum i next p...

VB中迴圈結構FORi1to10step2的步長是

for i 1 to 10 step 2步長為2 意思是 每次加 2 i被賦值如下13 579然後就停止迴圈了 步長即step 後面的數字,如果for 語句後沒有step關鍵字則預設的步長為1。在這裡有step 2,步長為2.虧你問得出,上都寫了 setp 2 了你還來問步長是多少?就好比你和一個人...