vb題目 輸出5 5的矩陣,其中元素是隨機生成的1 100的整數

2021-04-19 06:28:43 字數 5102 閱讀 9743

1樓:匿名使用者

private sub command1_click()randomize

form1.cls

dim c, e as integer

c = 0

e = 0

dim d as double

d = 1

dim a(4, 4) as stringfor i = 0 to 4

for j = 0 to 4

f = format(int(rnd * 100 + 1), "0,0")

if i = j or i + j = 4 then c = c + f: d = d * f

if f > e then e = f

a(i, j) = f

next

print a(i, 0) & " " & a(i, 1) & " " & a(i, 2) & " " & a(i, 3) & " " & a(i, 4)

next

print "對角線來的自

和為:" & c

print "對角線的

積為:" & d

print "最大的元素為:" & e

end sub

vb 關於陣列的問題1.利用隨機函式生成一個4*5的矩陣(二維陣列),範圍是[1,100]之間的整數,求所有元

2樓:匿名使用者

dim a%(4, 5)

private sub command1_click() '產生並bai輸出

for i = 1 to 4

for j = 1 to 5

a(i, j) = int(rnd * 100) '[1,100]print a(i, j);

next j

print '換行

next i

end sub

private sub command2_click() '求最小du值

max = a(1, 1) '最大值zhi的初始值為dao第回一個答元素

for i = 1 to 4

for j = 1 to 5

if max < a(i, j) thenmax = a(i, j)

end if

next j

next i

print "最大值為:"; max

end sub

3樓:匿名使用者

function t_rand()

s = ""

dim a(0 to 4, 0 to 5) as integermax = 0

for i = 0 to 3

for j = 0 to 4

a(i, j) = int((100 * rnd) + 1)if a(i, j) > max then max = a(i, j)

s = s & a(i, j) & vbtab '  debug.print a(i, j)

next j

s = s & vbcrlf

'debug.print

next i

s = s & "max=" & max

form1.text1.text = s

end function

vb程式設計題: 隨機生成一個4行9列的矩陣,矩陣元素為10-99之間的隨機整數.列印顯示.

4樓:山舟

option base 1

private sub form_click()dim a(36) as integer, b(6, 6) as integer, i as integer, j as integer, num as integer

print "原矩陣:"

randomize

for i = 1 to 36

a(i) = int((99 - 10 + 1) * rnd + 10)

print a(i);

num = num + 1

if num mod 9 = 0 then printnext

for i = 1 to 35

for j = 1 to 36 - i

if a(j) > a(j + 1) thent = a(j)

a(j) = a(j + 1)

a(j + 1) = t

end if

next

next

print "排序後矩陣:"

for i = 1 to 36

print a(i);

num = num + 1

if num mod 6 = 0 then printnext

print "主對角線上數字為:"

for i = 1 to 6

print a((i - 1) * 6 + i);

next

print

end sub

vb題:使用隨進函式產生0~9之間的隨機整數形成一個5階矩陣元素,計算矩陣元素之和

5樓:匿名使用者

private sub command1_click()dim a(1 to 5, 1 to 5)

text1.text = ""for i = 1 to ubound(a, 1)

for j = 1 to ubound(a, 2)randomize

a(i, j) = int(10 * rnd)text1.text = text1.text & str(a(i, j))

next j

text1.text = text1.text & vbcrlfnext iend sub

6樓:匿名使用者

**抄襲sub trygo()

dim a(4, 4) as integer, str as string

dim i as integer, j as integerfor i = 0 to 4

for j = 0 to 4

a(i, j) = int(10 * rnd)str = str & a(i, j) & " "

next j

str = str & vbcr

next i

debug.print str

end sub

輸出bai成du

果zhi

dao4 4 6 1 4

5 8 5 4 5

2 6 4 6 8

3 3 2 1 5

2 5 3 8 4

vb中利用隨機函式產生25個100到999之間的整數,構成5*5矩陣,輸出該矩陣,很急,謝謝

7樓:萍水e相逢

和bai 1 樓不一

du樣,

zhi我dao用到版

了權 text框

private sub command1_click()dim a(1 to 25) as integerdim i as integer

text1.text = ""

for i = 1 to 25

randomize

a(i) = int(900 * rnd + 100)text1.text = text1.text + cstr(a(i))

if i mod 5 = 0 then

text1.text = text1.text + vbcrlfelse

text1.text = text1.text + vbtabend if

next i

end sub

8樓:

private sub command4_click()dim a(24) as integer

call getrandomnumber(a)call printnumber(a)

end sub

private sub getrandomnumber(byref r() as integer)

randomize

dim i as integer

for i = 0 to 24

r(i) = int(900 * rnd()) + 100next i

end sub

private sub printnumber(byref r() as integer)

dim s as string

dim i as integer

dim j as integer

for i = 0 to 4

s = ""

for j = 0 to 4

s = s & vbtab & r(i * 5 + j)next j

debug.print s

next i

end sub

9樓:匿名使用者

private sub form_click()dim a(24), i, k as integerrandomize

for i = 0 to 24

a(i) = int(900 * rnd + 100)next i

for i = 1 to 25

print a(i - 1),

k = k + 1

if k mod 5 = 0 then print chr(13) & chr(10)

next i

end sub

vb程式設計題,編寫程式,輸出一個5*5矩陣,該矩陣對角線元素值為1,其他元素均為0。

10樓:匿名使用者

private sub command1_click()dim i as integer, j as integer, str as string

for i = 1 to 5

str = ""

for j = 1 to 5

if i = j or i + j = 6 thenstr = str & "1" & vbtabelse

str = str & "0" & vbtabend if

next

debug.print str

next

end sub

vb矩陣轉置,VB。求矩陣的轉置矩陣

option explicit private sub command1 click text1.text text2.text dim i as integer for i 1 to 24 text1.text text1 int rnd 90 10 if i mod 4 0 then text1...

求人解這VB題目,VB的題目 幫幫我吧

vb題目求解 完整 如下 dim s1,s2,l as doubledim i as integer l 1 s1 0 for i 1 to 24 s1 s1 1000 l i 1 next i s2 0 for i 1 to 24 s2 s2 1000 i 1 100next i if s1 s2...

vb編寫程式輸出100300之間的所有素數

private function isprime byref n as integer as boolean 此函式用於判斷一個數是否素數dim j as integer isprime true for j 2 to n 1 if n mod j 0 then isprime false exit...