在网上看了一些网友的答案,不是很满意!于是自己写了一个
#include <stdio.h>
#include <ctype.h>
void show_arr(int arr[][5], int n);
void store_date(double arr[][5]);
void average_per_row(const double arr[], int n);
void average(const double arr[][5], int len);
void find_max(const double arr[][5], int len);
int main(void)
{
double arr[3][5] = { 0 };
store_date(arr);
for (int i = 0; i < 3; i++)
average_per_row(arr[i], i+1);
average(arr, 3);
find_max(arr, 3);
getchar();
return 0;
}
void show_arr(int arr[][5], int n)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++)
printf("%4d", arr[i][j]);
putchar('\n');
}
}
void store_date(double arr[][5])
{
for (int i = 0; i < 3; i++)
for (int j = 0; j < 5; j++)
scanf("%lf", &arr[i][j]);
}
void average_per_row(const double arr[],int n)
{
double avg = 0;
for (int i = 0; i < 5; i++)
avg += arr[i];
avg /= 5;
printf("The average of the %d row is %g\n", n, avg);
}
void average(const double arr[][5], int len)
{
double avg = 0;
for (int i = 0; i < len; i++)
for (int j = 0; j < 5; j++)
avg += arr[i][j];
avg = avg / (len * 5);
printf("The average of the data is %g\n", avg);
}
void find_max(const double arr[][5], int len)
{
double max = arr[0][0];
for (int i = 0; i < len; i++)
for (int j = 0; j < 5; j++)
max = max > arr[i][j] ? max : arr[i][j];
printf("The maximun of the data is %g\n", max);
}
标签:13,avg,int,double,void,arr,++,Plus,Primer From: https://www.cnblogs.com/alien-han/p/16949996.html