[問題] 2維陣列產生亂數
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
05/24 13:57, 5F