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
c產生隨機數 不重複,C 產生隨機數 不重複
private const int num 3 數目 private const int maxvalue 5 最大數 private const int minvalue 1 最小數 public int sort int num return num public int getnum int ...
c 中產生不重複的隨機數
解題思路 這個題目要解決兩個問題 一是產生隨機數 二是不能重複。第一個問題 產生隨機數。在c 中要產生隨機數必須用到兩個函式 srand 和rand 函式,使用這兩個函式必須包含標頭檔案 其中rand 是產生一個偽隨機數,比如 int a rand 函式返回值的取值範圍是int型別的取值範圍,如果要...
vb程式設計如何產生1到1000的隨機數
不知道你要如何顯示,以下是在窗體上顯示的 private sub form click dim i as integer dim x as integer dim s as string for i 1 to 3 randomize x int rnd 1000 1 1 1 s s x next i...