Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
3203 王冯俊 二维数组输出(1) C++ 编译错误 0 0 MS 0 KB 1230 2019-12-14 14:33:12

Tests(0/0):


#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; }


测评信息: