C语言输入n个值,计算并输出最大值、最小值、总和和平均分;
时间: 2024-05-05 07:16:20 浏览: 58
```
#include <stdio.h>
int main() {
int n, i, max, min;
float sum = 0, avg;
printf("请输入n的值:");
scanf("%d", &n);
int a[n];
printf("请输入%d个整数:\n", n);
for(i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
if(i == 0) {
max = a[i];
min = a[i];
}
else {
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
}
avg = sum / n;
printf("最大值:%d\n最小值:%d\n总和:%g\n平均分:%g", max, min, sum, avg);
return 0;
}
```
阅读全文