提交时间:2019-12-14 14:33:12

运行 ID: 3203

#include <cstdio> double funAverage(int *p, int n); int funMax(int p[][3], int n); int funMin(int (*p)[3], int n); int main(int argc, char const *argv[]) { int a[4][3], num; size_t i, j, ROWS, COLS, totalnum; ROWS = sizeof(a)/sizeof(a[0]); COLS = sizeof(a[0])/sizeof(a[0][0]); totalnum = ROWS * COLS; printf("Input %dx%d integer matrix:\n", ROWS, COLS); i = 0; while (i < ROWS) { j = 0; while (j < COLS) { if (scanf("%d", &num) == 1) { a[i][j] = num; j++; } } i ++; } printf("\n"); printf("Max: %d\n", funMax(a,4)); printf("Min: %d\n", funMin(a,4)); printf("Average: %g\n", funAverage(a[0],12)); return 0; } double funAverage(int *p, int n) { int i; double sum = 0.0; for (i = 0; i < n; ++i) sum += p[i]; return (double)(sum/n); } int funMax(int p[][3], int n) { int i,j, cols, amax = p[0][0]; cols = sizeof(p[0])/sizeof(p[0][0]); for (i = 0; i < n; ++i) for (j = 0; j < cols; ++j) if (p[i][j] > amax) amax = p[i][j]; return amax; }