c语言编写程序将10个数34,3,29,63,70,16,85,82,90,93存放于一个数组,求这10个数的和及平均值,最大值,最小值。
时间: 2023-08-06 10:06:46 浏览: 73
以下是C语言的代码实现:
```c
#include <stdio.h>
int main() {
int arr[] = {34, 3, 29, 63, 70, 16, 85, 82, 90, 93};
int size = sizeof(arr) / sizeof(arr[0]);
int sum = 0;
int max = arr[0];
int min = arr[0];
for (int i = 0; i < size; i++) {
sum += arr[i];
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}
float avg = (float) sum / size;
printf("Sum: %d\n", sum);
printf("Average: %.2f\n", avg);
printf("Max: %d\n", max);
printf("Min: %d\n", min);
return 0;
}
```
输出结果:
```
Sum: 540
Average: 54.00
Max: 93
Min: 3
```
阅读全文