九種求和方法

2021-07-11 05:02:10 字數 3070 閱讀 9368

(一) option explicit

private sub command1_click()

dim i as integer

dim a(10) as integer

dim sum as integer

randomize

for i = 1 to 10

a(i) = int(rnd * 1000) + 1

sum = sum + a(i)

next i

print sum

end sub

(二) private sub command1_click()

clsdim n as integer, s as integer

dim a(10) as integer

n = 1

while n <= 10

a(n) = int(rnd * 1000)

n = n + 1

wend

n = 1

while n <= 10

print a(n)

n = n + 1

wend

s = 0

n = 1

while n <= 10

s = s + a(n)

n = n + 1

wend

print s

end sub

(三) dim sum as integer

dim i as integer

dim a as integer

private sub command1_click()

sum = 0

for i = 1 to 10

randomize

a = int(1000 * rnd)

sum = sum + a

msgbox "10個隨機數和為:" & sum

next

end sub

(四)dim sum as integer

dim i as integer

dim a as integer

private sub command1_click()

sum = 0

for i = 1 to 10

randomize

a = int(1000 * rnd)

sum = sum + a

next

msgbox "10個隨機數和為:" & sum

do while i <= 10

randomize

a = int(1000 * rnd)

sum = sum + a

msgbox "10個隨機數和為:" & sum

loop

end sub

(五) dim sum as integer

dim i as integer

dim a as integer

private sub command1_click()

sum = 0

for i = 1 to 10

randomize

a = int(1000 * rnd)

sum = sum + a

next

msgbox "10個隨機數和為:" & sum

i = 1

do until i > 10

randomize

a = int(1000 * rnd)

sum = sum + a

i = i + 1

loop

msgbox "10個隨機數和為:" & sum

end sub

(六) dim sum as integer

dim i as integer

dim a as integer

private sub command1_click()

i = 1

dorandomize

a = int(1000 * rnd)

sum = sum + a

i = i + 1

loop while i <= 10

msgbox "10個隨機數和為:" & sum

i = 1

dorandomize

a = int(1000 * rnd)

sum = sum + a

i = i + 1

loop until i > 10

msgbox "10個隨機數和為:" & sum

end sub

(七)private sub command1_click()

clsfont.size = 70

print f(100)

end sub

private function f(x as integer) as long

if x = 1 then

f = x

else

f = x + f(x - 1)

end if

end function

(八) dim sum as integer

dim i as integer

dim a as integer

private sub command1_click()

i = 1

dorandomize

a = int(1000 * rnd)

sum = sum + a

i = i + 1

loop while i <= 10

msgbox "10個隨機數和為:" & sum

end sub

(九)dim sum as integer

dim a as integer

dim i as integer

private sub command1_click()

i = 1

dorandomize

a = int(1000 * rnd)

sum = sum + a

i = i + 1

loop until i > 10

msgbox "10個隨機數和為:" & sum

end sub

九種求和方法

一節vb課我終於完成了這個偉大的方法 一 option explicit private sub command1 click dim i as integer dim a 10 as integer dim sum as integer randomize for i 1 to 10 a i in...

迴圈九種方法

今天老師讓用九種方法做 隨機出十個數並求和 但是好像有點雲裡霧裡的,我只會六個,那三個是啥。好像亂了。嗚呼哀哉,先做乙個再說吧!一,第一種方法 private sub command1 click dim i as integer dim a 10 as integer randomize for ...

激勵自己地九種方法

1 調高目標 真正能激勵你奮發向上的是 確立乙個既巨集偉又具體的遠大目標。許多人驚奇發現,他們之所以達不到自己孜孜以求的目標,是因為他們的主要目標太小,而且太模糊,使自己失去主動力。如果你的主要目標不能激發你的想象力,目標的實現就會遙遙無期。2 離開舒適區 不斷尋求挑戰,體內就會發生奇妙的變化,從而...