采用指针法,输出二维数组各行的最大值和平均值
自己写的代码如下。是不对的。程序代码:
#include <stdio.h> double fun1(double *p1); double fun2(double *p2); int main() { double ss[3][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15}}; double (*p)[5]; p=ss; printf("第一组数平均值=%.1f\n", fun1(p)); printf("第二组数平均值=%.1f\n", fun1(p+1)); printf("第三组数平均值=%.1f\n", fun1(p+2)); printf("第一组数最大值=%.1f\n", fun2(p)); printf("第二组数最大值=%.1f\n", fun2(p+1)); printf("第三组数最大值=%.1f\n", fun2(p+2)); m = 100 / 20; printf("%d\n ",m); return 0; } double fun1(double *p1) { double s = 0, k = 0; for (int i = 0; i < 5; i++) { s += *p1; } k = s / 5; return k; } double fun2(double *p2) { int i=0, is=0; double m = 0; for (int i = 0; i < 5; i++) { if (m < *p2) { m = *p2; } } return m; }