C语言编程:求double型二维数组a的最大值和最小值;急要,能把程序写全最好,谢谢
将求最大值和最小值定义为函数doublefmax(doublea[][m],intm,intn,double*pmin)。...
将求最大值和最小值定义为函数double fmax(double a[][m],int m,int n,double *pmin)。
展开
1个回答
展开全部
double fmax(double a[][m],int n,double *pmin) { // m必须是常量
int i,j;
double max;
max = *pmin = a[0][0];
for(i = 0; i < n; ++i) {
for(j = 0; j < m; ++j) {
if(max < a[i][j]) max = a[i][j];
if(*pmin > a[i][j]) *pmin = a[i][j];
}
}
return max;
}
int i,j;
double max;
max = *pmin = a[0][0];
for(i = 0; i < n; ++i) {
for(j = 0; j < m; ++j) {
if(max < a[i][j]) max = a[i][j];
if(*pmin > a[i][j]) *pmin = a[i][j];
}
}
return max;
}
追问
能不能把主函数也发来,谢谢
追答
/*
输入二维数组的行、列(空格隔开) : 5 6
57.91 73.14 53.42 2.54 59.45 57.04
35.36 94.18 91.76 28.88 75.24 97.18
42.43 80.34 41.45 27.02 71.13 96.58
69.48 4.79 81.43 34.01 63.56 12.04
87.45 62.69 2.36 41.52 51.98 89.60
max = 97.18, min = 2.36
Press any key to continue
*/
#include
#include
#include
#define N 10
#define M 10
double fmax(double a[][M],int n,int m,double *pmin) {
int i,j;
double max;
max = *pmin = a[0][0];
for(i = 0; i a[i][j]) *pmin = a[i][j];
}
}
return max;
}
void Show(double a[][M], int n,int m) {
int i,j;
for(i = 0; i N) ? N : n;
m = (m > M) ? M : m;
srand((unsigned)time(NULL));
for(i = 0; i < n; ++i) {
for(j = 0; j < m; ++j)
a[i][j] = 0.01 * (rand()%9900 + 100);
}
Show(a,n,m);
max = fmax(a,n,m,&pmin);
printf("max = %5.2lf, min = %5.2lf\n",max,pmin);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询