VB程式設計「求1到1000以內所有奇數之和」(do while結構)

2021-04-28 17:33:12 字數 1241 閱讀 8649

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

編寫求1到100之間奇數的和。用vb語言。 10

3樓:匿名使用者

private sub command1_click()dim i, sum1, sum2 as integersum1 = 0

sum2 = 0

for i = 1 to 100

if i mod 2 = 1 then

sum1 = sum1 + i

else

sum2 = sum2 + i

end if

next i

print "奇數

bai和du為zhi" & sum1

print "偶數

dao和為" & sum2

end sub

4樓:匿名使用者

private sub form_click()dim i as long

dim sum as long

sum = 0

for i = 1 to 100 step 2sum = sum + i

next i

print sum

end sub

急求vb程式設計100以內的加法運算

dim n1,n2,ztol,tm private sub mand1 click randomize da tm tm 1 n1 int rnd 100 n2 int rnd 100 ti.caption n1 n2 end sub private sub mand2 click pdend su...

VB程式設計急求答案

option explicit dim basesize as singleprivate sub form load basesize label1.fontsizeend sub private sub timer1 timer if label1.fontsize 1.5 100 then l...

vb設計程式,統計1000以內能被7整除的正整數的個數

private sub form click dim n as integer,i as integerfor i 7 to 1000 if i mod 7 0 then n n 1next print n end sub private sub form load dim totali,i as ...