C语言,求一个二维数组中偶数个数,最大值,最小值和平均值,并输出
时间: 2023-05-21 07:05:46 浏览: 494
请看下面的C语言代码,可以实现你所要求的功能:
```c
#include <stdio.h>
int main() {
int arr[100][100];
int rows, cols, i, j, count = 0, sum = 0, max = -2147483648, min = 2147483647;
double avg;
printf("请输入二维数组的行数和列数:");
scanf("%d%d", &rows, &cols);
printf("请输入二维数组的%d个元素:\n", rows * cols);
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
scanf("%d", &arr[i][j]);
if (arr[i][j] % 2 == 0) {
count++;
if (arr[i][j] > max) {
max = arr[i][j];
}
if (arr[i][j] < min) {
min = arr[i][j];
}
sum += arr[i][j];
}
}
}
avg = (double)sum / count;
printf("数组中偶数个数为:%d\n", count);
printf("数组中偶数的最大值为:%d\n", max);
printf("数组中偶数的最小值为:%d\n", min);
printf("数组中偶数的平均值为:%.2lf", avg);
return 0;
}
```
输入样例:
```
请输入二维数组的行数和列数:2 3
请输入二维数组的6个元素:
1 2 3 4 5 6
```
输出样例:
```
数组中偶数个数为:3
数组中偶数的最大值为:6
数组中偶数的最小值为:2
数组中偶数的平均值为:4.00
```
阅读全文
相关推荐
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)