输入m个数,求其最大数、最小数和平均值C语言代码
时间: 2024-05-22 09:15:50 浏览: 79
求最大数、最小数、平均值
#include <stdio.h>
int main() {
int m, num;
int max = -1000000, min = 1000000, sum = 0;
float avg;
printf("请输入数字的个数:");
scanf("%d", &m);
for (int i = 0; i < m; i++) {
printf("请输入第%d个数字:", i + 1);
scanf("%d", &num);
if (num > max) {
max = num;
}
if (num < min) {
min = num;
}
sum += num;
}
avg = (float)sum / m;
printf("最大数为:%d\n", max);
printf("最小数为:%d\n", min);
printf("平均值为:%.2f\n", avg);
return 0;
}
阅读全文