回覆列表
  • 1 # 科普育兒

    利用隨機數生成兩個矩陣(資料不一定相同,前者30-70範圍,後者101-135)

    (1)將兩個矩陣相加結果放入c矩陣中。

    for i = 1 to 4

    for j = 1 to 4

    c(i, j) = a(i, j) + b (i, j)

    next j

    next i

    (2)將a矩陣轉置

    for i = 2 to 4

    for j = 1 to i – 1

    t = a(i, j): a(i, j) = a(j, i): a(j, i) = t

    next j

    next i

    (3)統計c矩陣中最大值和下標

    dim max%, maxi%, maxj%

    max = c(1, 1): maxi = 0: maxj = 0

    for i = 1 to 4

    for j = 1 to 4

    if c(i, j) > max then

    max = c(i, j): maxi = i: maxj = j

    end if

    next j

    next i

    (4)以下三角形式顯示a矩陣,上三角形式顯示b矩陣

    for i = 1 to 4

    for j = 1 to i

    print a(i, j); space(2);

    next j

    print

    next i

    print "輸出b上三角元素"

    for i = 1 to 4

    print tab(i * 5);

    for j = i to 4

    print b(i, j);

    next j

    print

    next i

    (5)將a矩陣第一行與第三行對應元素交換位置

    for j = 1 to 4

    t = a(1, j): a(1, j) = a(3, j): a(3, j) = t

    next j

    (6)求a矩陣 矩陣條對角線元素之和

    sum = 0

    for i = 1 to 4

    sum = sum + a(i, i) + a(i, 5 - i)

    next i

    (7)將a矩陣按列的次序把各元素放入一維陣列d中,顯示結果

    dim d%(16)

    for i = 1 to 4

    for j = 1 to 4

    d(k) = a(j, i): k = k + 1

    next j

    next i

    print "d一維陣列無素為:"

    for k = 0 to 15

    print d(k);

    next k

  • 中秋節和大豐收的關聯?
  • 合同招標檔案法律效力優先順序?