以下是 C 语言代码示例:
#include <stdio.h>
#define MAX_NUM 30
int main()
{
int a[MAX_NUM];
int i = 0, j;
int sum = 0;
int num;
int avg;
printf("请输入数字(-1结束):\n");
scanf("%d", &num);
while (num != -1) {
a[i++] = num;
sum += num;
scanf("%d", &num);
}
avg = sum / i;
printf("avg=%.1f\n", (float)avg);
for (j = i - 1; j >= 0; j--) {
printf("%d ", a[j]);
if ((j + 1) % 5 == 0) {
printf("\n");
}
}
return 0;
}