用c语言求二维数组数中的最大值、 最小值和平均值,并求有多少个数超过 平均值。要求:数组元素值由用户输入。
时间: 2024-05-20 09:16:57 浏览: 20
#include <stdio.h>
int main()
{
int row, col;
printf("请输入矩阵行数和列数:\n");
scanf("%d%d", &row, &col);
int matrix[row][col];
printf("请依次输入矩阵元素:\n");
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
scanf("%d", &matrix[i][j]);
}
}
int max = matrix[0][0], min = matrix[0][0], sum = 0, count = 0;
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
if(matrix[i][j] > max)
{
max = matrix[i][j];
}
if(matrix[i][j] < min)
{
min = matrix[i][j];
}
sum += matrix[i][j];
}
}
double avg = (double)sum / (row * col);
printf("矩阵的最大值为:%d,最小值为:%d,平均值为:%lf\n", max, min, avg);
for(int i=0; i<row; i++)
{
for(int j=0; j<col; j++)
{
if(matrix[i][j] > avg)
{
count++;
}
}
}
printf("有%d个数超过平均值。\n", count);
return 0;
}
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)