VB中運用計數迴圈結構計算出

時間 2021-05-04 21:50:00

1樓:匿名使用者

private sub form_click()dim s as integer, i as integers = 0

i = 1

dos = s + i

i = i + 1

loop until i = 101

print "s="; s

end sub

執行結果:

s= 5050

2樓:匿名使用者

vb你都會,地球人真是無法阻擋你了,

vb中怎樣使用迴圈結構對a(6)的6個元素賦值1,2,3,4,5,6.並用print語句顯示?

3樓:無敵手了啊

最終使用迴圈結構對六個元素賦值。

4樓:獅子薯片

如果說需要進行相應的應該迴圈顯示的話,我覺得你是可以相關參考相應的說明書。

vb利用迴圈結構程式設計計算表示式1+1/2+1/3+.....+1/n的值

5樓:數學與計算機程式設計

private sub command1_click()static n as long, valsum as doubleselect case command1.captioncase "計算"

valsum = 0

dim i as long

n = inputbox("pleace input integer n:", "inputbox", 10)

command1.caption = "顯示"

for i = 1 to n

valsum = valsum + 1 / inext i

case "顯示"

label1.caption = "n=" + cstr(n)text1.text = valsum

command1.caption = "計算"

end select

end sub

private sub form_load()text1.enabled = falsetext1.text = ""

command1.caption = "計算"

command1.fontbold = truecommand1.fontsize = 22command1.fontname = "宋體"

text1.fontname = "times new roman"

text1.fontbold = truetext1.fontsize = 22

end sub

求解1^3+3^3+5^3+…………(2n-1)^3=????? 用vb迴圈結構程式編寫的**

6樓:網海1書生

那個推薦答案是錯的,他沒有累加,所以得出的結果是最後那個數的計算值private sub form_click()dim i as long, n as long, s as double

n = val(inputbox("請輸入n值"))for i = 1 to n

s = s + (2 * i - 1) ^ 3next

msgbox "計算結果為" & s

end sub

7樓:匿名使用者

option explicit

private function nsancf(n as long) as double

dim djg as double

for n = 1 to 2 * n - 1 step 2djg = n * n * n

next n

nsancf = djg

end function

private sub form_click()dim d as double, n as longn = inputbox("請輸入數字")print str(nsancf(n))

end sub

8樓:

請先學會化簡後在程式設計計算,那樣效率會高很多.