[/size]
[size=4]#include <stdio.h>
#include <stdlib.h>
int calc(int *a, int N);
int main(void) {
int N = 0;
printf("N=");
scanf("%d", &N);
if ((N <= 0) || (N > 10)) {
printf_s("请输入小于等于10的正整数");
getchar();
exit(-1);
} else if (N == 1) {
printf_s("n1=");
scanf("%d", &N);
printf("Max=%d\nMin=%d\nAvg=%d", N, N, N);
while (1) {
exit(0);
}
}
int x[N];
for (int i = 0; i < N; ++i) {
printf_s("n%d=", i + 1);
scanf("%d", &x[i]);
}
calc(x, N);
return 0;
}
int calc(int *a, int N) {
int max, min;
int sum = 0;
max = a[0];
min = a[0];
for (int i = 0; i < N; ++i) {
if (max < a[i]) {
max = a[i];
}
if (min > a[i]) {
min = a[i];
}
sum += a[i];
}
float avg = sum / N;
printf("Max=%d\nMin=%d\nAvg=%.2f", max, min, avg);
return 0;
}
#include <stdio.h >
int main()
{
int max, min, i,N,M;
printf_s("请输入个数:");
scanf_s("%d", &N);
M = N;
int Sum = 0;
float avg;
while (N)
{
printf_s("请输入一个整数:");
scanf_s("%d",&i);
Sum =Sum+ i;
if (N == M)
{
max = i;
min = i;
}
if (i > max) { max = i; }
if (i < min) { min = i; }
N--;
}
avg = Sum / M;
printf_s("最大值=%d,最小值=%d,平均值=%f", max,min,avg);
}