[問題] 2維陣列產生亂數

看板C_and_CPP作者 (Roca視化)時間15年前 (2010/05/24 00:39), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
D:\98_教學\程式語言\0517_2D_rand.cpp 1 // B3.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdlib.h> void assignRand(int b[][5], int r, int c); void findMax(int b[][5], int r, int c, int maxR[]); int _tmain(int argc, _TCHAR* argv[]) { int a[3][5]; int rowMax[3]; int i, j; assignRand(a, 3, 5); for(i=0; i<3; i++) {// row for(j=0; j<5; j++) // col printf("%5d", a[i][j]); printf("\n"); } findMax(a, 3, 5, rowMax); for(i=0; i<3; i++) printf("max = %d\n", rowMax[i]); system("pause"); return 0; } void findMax(int b[][5], int r, int c, int maxR[]) { int i, j, max; for(i=0; i<r; i++) {// row max = b[i][0]; for(j=0; j<c; j++) // col if(b[i][j] >max) max = b[i][j]; maxR[i] = max; } } void assignRand(int b[][5], int r, int c) { int i, j; for(i=0; i<r; i++) // row for(j=0; j<c; j++) // col b[i][j] = rand() %10 +1; } 我想請問..void assignRand(int b[][5], int r, int c) 的 int b[][5] 是什麼意思?? 為什麼要設5@@ 他把a傳進來 意思是r=3 c=5嗎 可以只寫 b[][]嗎 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.224.174

05/24 01:50, , 1F
傳陣列至少最後一個維度的大小都要在, 剩下其他維度的
05/24 01:50, 1F

05/24 01:50, , 2F
資訊都會消失掉
05/24 01:50, 2F

05/24 12:26, , 3F
樓上反了 第一個維度會消失 其他必須在
05/24 12:26, 3F

05/24 13:28, , 4F
@@
05/24 13:28, 4F

05/24 13:57, , 5F
謝謝LPH大提醒 ^^
05/24 13:57, 5F
文章代碼(AID): #1B-Lez36 (C_and_CPP)