1樓:匿名使用者
給你個思路。
首先,定義20個陣列。
然後在過程里弄個for迴圈,比如for i = 1 to 20利用隨機函式,生成65~90之間的函式,賦值到變數,比如 str=int((90 - 65 + 1) * rnd + 65)
再弄個for迴圈,比如for j = 1 to i判斷是否重複 if 陣列名(j)=str thencall 過程
exit sub
end if
next
然後給陣列賦值 比如陣列名(i)=chr(str)next
end sub
2樓:
這題挺麻煩,還一點分都沒有...
3樓:沙慧月
dim a()
private sub command1_click()redim preserve a(0)
do until ubound(a) = 20randomize
j = int(rnd * 26 + 65)temp = chr(j)
for k = 0 to ubound(a)if a(k) = temp then exit fornext
if k = ubound(a) + 1 thenredim preserve a(ubound(a) + 1)a(ubound(a)) = temp
end if
loop
for i = 1 to 19
for j = i + 1 to 20
if asc(a(i)) > asc(a(j)) then temp = a(i): a(i) = a(j): a(j) = temp
next j
next i
for y = 1 to 20
if y mod 6 = 0 then
else
print a(y);
end if
next
end sub
vb 隨機產生20個不重複的a~z之間的字母(包括a 和z)字元,放在字元陣列中.求 出其 5
4樓:匿名使用者
dim a(20) as string
dim b(26, 2) as integerfor i = 1 to 26
b(i, 1) = 64 + i
b(i, 2) = 0
next i
dim n as integer, m as integer, s as string
n = 1
s = ""
do while n <= 20
randomize
m = int(rnd * 26) + 1if b(m, 2) = 0 then
a(n) = chr(b(m, 1))
b(m, 2) = 1
n = n + 1
end if
loop
dim max as integer, min as integermax = 65
min = 90
for i = 1 to 20
s = s & a(i) & " "
next i
print s
隨機產生15個不重複的a-z的大寫字母,存放在字元陣列中(vb解決此題)
5樓:木木的哥哥
randomize
dim mychar(15),i%,j%
for i=1 to 15
mychar(i)=chr(int(rnd*26+65))for j=1 to i-1
if mychar(j)=mychar(i) theni=i-1
exit for
end if
next
next
最後的結果儲存在mychar(1)到mychar(15)中,資料型別忘記了,自己在定義陣列的時候寫上版
吧,還有好象可以權
用dim mychar(1 to 15)吧,我沒有vb,你自己試一下。
vb程式設計題,用陣列實現隨機輸出十個小寫英文字母
6樓:匿名使用者
private sub form_click()dim a(10) as string
dim i as integer, k as integerform1.autoredraw = truerandomize
print "產生的十個字母是:"
for i = 1 to 10
a(i) = chr(int(rnd * 26 + 97))print a(i);
next
for i = 1 to 10
if a(i) = chr(97) then k = k + 1next
print "出現專
字母 "; chr(97); " 的個數屬是:"; k
end sub
7樓:聽不清啊
private sub command1_click()dim a(10) as string * 1randomize
for i = 1 to 10
a(i) = chr(int(rnd * 26) + 97)next i
for i = 1 to 10
print a(i);
next i
end sub
vb程式設計隨機產生10個不重複的a到z的大寫字母,要求將10個字元,最大和最小字
8樓:
private sub command1_click()const n = 10
dim a(n) as string
for i = 1 to 10
doflag = true
a(i) = chr(asc("a") + int(rnd * 26))
for j = 1 to i - 1
if a(i) = a(j) then flag = false: exit for
next j
loop until flag
next i
print "隨機不重複的字串是"
for i = 1 to n
print a(i);
next i
max = a(1): min = a(1)for i = 1 to n
if max < a(i) then max = a(i)if min > a(i) then min = a(i)next i
print "最大的字元是:" & maxprint "最小的字元是:" & minend sub
vb程式設計 急求 隨機產生n個1 100之間的數(包含1和
新增乙個command控制項即可,如下 private sub command1 click dim a 5 z,s,max,min as integer print 生成的數字 for i 1 to 5 陣列裡面有5個不同數值a1,a2,a3,a4,a5,此處i的最大值n對應dim中的a n 可以...
vb程式設計應用二維陣列產生隨機矩陣55並實現矩陣
珈藍惜夢 vb源程式如下 option base 1 private sub command1 click dim a 5,5 as integer,b 5,5 as integer for x 1 to 5 for y 1 to 5 a x,y int 10 rnd 90 隨機產生兩位數的整數 p...
excel中如何生成不重複的多個隨機數
先在a1 a8中輸入相同的公式 int rand 15 1 再在b1中輸入下面公式,並拖動複製到b8格,如果a列中有重複,b列對應的格會顯示大於1的數字,等於1為不重複。countif a 1 a 8,a1 然後按鍵盤上方的f9功能鍵,直到b列格中都是1,就行了。 一種思路是,先 生成1 15間的一...