1樓:匿名使用者
private sub command1_click()dim i as integer, t as integer, sum
randomize
for i = 1 to 12
t = int(rnd * (90 - 10 + 1) + 10)if t mod 2 = 0 then sum = sum + tprint t;
next
print sum
end sub
2樓:劍小風
private sub form_load() '窗體載入事件dim a(11) as integer
dim i as integer, k as integershow
randomize
for i = 0 to 11
a(i) = int(rnd * 80 + 10)print a(i);
next i
for i = 0 to 11
if a(i) mod 2 = 0 thenk = k + a(i)
print a(i);
end if
next i
print "所有偶數和為:" & k
end sub
3樓:匿名使用者
公式rnd*(max-min)+min產生min到max之間的隨機數,用randomize(time)產生隨機數種子,以避免隨機數列週期性重複,大致**如下:
dim ary(11) as integerdim i as integer
randomize(time)
for i = 0 to 11 step 1ary(i) = rnd*(90-10)+10next i
執行完上面**後ary()中的就是你所需要的資料。
用vb語言求隨機產生並顯示10個1~10之間的整數,分別求出其中的所有奇數之和和偶數之積
4樓:喻元愷
dim s(10) as integer
dim sum1 as integer = 0dim sum2 as integer = 0for i as integer = 1 to 10s(i) = cint(int((10 * rnd()) + 1))next
for i as integer = 1 to 10if s(i) mod 2 = 0 thensum1 += s(i)
else
sum2 += s(i)
end if
me.textbox4.text += s(i).tostring() + " ,"
next
me.textbox4.text += " sum1=" + sum1.tostring() + ", sum2=" + sum2.tostring()
5樓:
private sub command1_click()dim a%(9),s%, m%
m = 1
for i = 0 to 9
a(i) = int(10* rnd + 1)if a(i) and 1 = 1 then s = s + a(i) else m = m * a(i)
print a(i)
next
print "奇數之和:" & s & ",偶數之積:" & mend sub
6樓:匿名使用者
private sub command1_click()dim a(1 to 10) as integerdim s, ss as integer
s = 1
for i = 1 to 10
a(i) = int((10 - 1 + 1) * rnd + 1)if a(i) mod 2 = 0 thens = s * a(i)
else
ss = ss + a(i)
end if
print a(i)
next
print s; ss
end sub
vb 求解答:隨機生成10個正整數,統計其中奇數和偶數的
7樓:匿名使用者
for i=1 to 10
temp = int(10*rnd) '隨機0-9 的數字if temp mod 2 then jishu=jishu+1next
oushu = 10-jishu
print "偶數個數:" & oushuprint "基數個數:" & jishu
vb程式設計利用隨機函式產生15個隨機整數,區間為10-90輸出其中最小的三個奇數的和 5
8樓:聽不清啊
private sub command1_click()dim a(10 to 90) as integerrandomize
for i = 1 to 15
x = int(81 * rnd) + 10a(x) = 1
print x;
next i
i = 11
while a(i) = 0
i = i + 2
wend
print i;
s = j
for j = i + 2 to 90 step 2if a(j) = 1 then
k = k + 1
s = s + j
print "+"; j;
if k = 2 then exit forend if
next j
print "="; s
end sub
9樓:匿名使用者
private sub command1_click()dim d(15) as integer
dim x as integer
dim num as integer
dim i as integer
dim j as integer
randomize
donum = 0
for i = 1 to 15
d(i) = int((81) * rnd + 10)if d(i) mod 2 = 1 then num = num + 1
next i
loop until num >= 3
'輸出15和數
for i = 1 to 15
print d(i);
next i
'排序for i = 1 to 14
for j = i + 1 to 15
if d(i) > d(j) then
x = d(i)
d(i) = d(j)
d(j) = x
end if
next j
next i
'輸出結果
x = 0
num = 0
for i = 1 to 15
if d(i) mod 2 = 1 thennum = num + 1
x = x + d(i)
print d(i);
end if
if num = 3 then exit fornext i
print "它們的和為:"; x
end sub
10樓:匿名使用者
要是產生的隨機數都是偶數怎麼辦?
利用高階語言程式設計(vb)隨機函式產生90個10~99之間的隨機整數,將其中的偶數按由小到大的順序排列…
用vb,隨機生成20個100以內的正整數,將其中的奇數和偶數分兩行顯示在窗體上? 20
11樓:匿名使用者
private sub form_activate()dim myarray(1 to 20) as integerdim myarray2(1 to 20) as integerdim myarray3(1 to 20) as integerdim j as integer
j = 1
dim k as integer
k = 1
dim i as integer
for i = 1 to 20
randomize
myarray(i) = (1 - 100) * rnd + 100if myarray(i) mod 2 = 0 thenmyarray2(j) = myarray(i)else
myarray3(k) = myarray(i)end if
j = j + 1
k = k + 1
next i
for j = 1 to 20
if myarray2(j) <> 0 thenprint myarray2(j);
end if
next j
for j = 1 to 20
if myarray3(j) <> 0 thenprint myarray3(j);
end if
next j
end sub
12樓:藍色無限
randomize
for i=1 to 20
r=rnd*100+1
if r mod 2 then
n=n+1
a(n)=r
else
m=m+1
a(m)=r
end if
next
for i=1 to n
print(a(n))
next
for i=1 to m
print(a(m))
next
c語言輸入兩個正整數m和n,求出區間的所有素數
最後的輸出迴圈有點問題 for int i 0 i x i printf d a i 因為你上邊已經x 你如果判斷條件裡寫成 for int i 0 i x i 程式是要崩的。除了1和自身之外沒有其它正整數因子的正整數稱為素數,也就是不用試1和自身 for j 2 j i j 改為 for j 2 ...
編寫程式,輸入正整數,計算並顯示該數的各位數字之和
include int sum int n return s int main 輸出 請輸入乙個正整數 12345 輸入的數為 12345 其各位之和為 15請按任意鍵繼續.include intmain printf 該數的各位數字之和 d sum 編寫乙個程式,其功能是輸入乙個三位數,計算並輸出...
正整數a除以7後的商從小數點後第一位起到某一位為止,所有數字上的數字之和為2019,問a是多少
任何乙個整數除以7,小數都會以285714 順序可以不一樣,可以使142857等 為週期迴圈的,這幾個數相加 27,2008除以27,餘10.這就說明有相加 10的兩個 或幾個 數為結尾,即28。所以小數點後的是以285714迴圈。所以只要小數點後第一位是2即可。比如a 9,a 17 a 2 7n ...