※ 引述《MAIDic (咩滴可)》之銘言:
你原本程式在function中存取陣列,邊界限制卻要去看全域變數,這樣不太好,
所以我在function的參數中增加兩個, 讓你把array大小傳進去
#include <stdio.h>
#include <stdlib.h>
void locateLargest(double** p_array, unsigned int p_row, unsigned int p_col);
int row;
int col;
double** array;
int main()
{
int i,j;
scanf("%d",&row);
scanf("%d",&col);
//*********dynamic memory allocate*********
array = (double**)malloc(row*sizeof(double*));
for(i=0;i<row;i++)
{
*(array+i)=(double*)malloc(col*sizeof(double));
}
//*********dynamic memory allocate********
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%lf",*(array+i)+j);
}
}
locateLargest(array,row,col);
//free就不寫了
}
void locateLargest(double** p_array, unsigned int p_row, unsigned int p_col)
{
double max=0;
unsigned int i,j,x,y;
for(i=0;i<p_row;i++)
{
for(j=0;j<p_col;j++)
{
if(*(*(p_array+i)+j)>max)
{
max=*(*(p_array+i)+j);
x=i;
y=j;
}
}
}
printf("%d%d",x,y);
}