我对 C 非常陌生,并且正在解决家庭作业问题。我们需要编写一个程序,从用户那里接收 10 个数字,然后输出平均数、最高数和最低数。我有看起来像正确的代码,但输出就差很多了。这是我到目前为止所拥有的
#include <stdio.h>
int main() {
int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10;
printf("Enter 10 grades sperated by commas, then press enter: ");
scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",num1,num2,num3,num4,num5,num6,num7,num8,&num9,&num10);getchar();
int numbers[] = {num1,num2,num3,num4,num5,num6,num7,num8,num9,num10};
int avg = (num1+num2+num3+num4+num5+num6+num7+num8+num9+num10)/10;
printf("The average is: %d",avg);
int high = num1;
for(int i=0; i<10; i++) {
if (numbers[i] > high) {
high = numbers[i];
}
}
printf("The highest grade is: %d",high);
int low = num1;
for(int i=0; i<10; i++) {
if (numbers[i] < low) {
low = numbers[i];
}
}
printf("The lowest number is: %d",low);
return 0;
}
如果有人可以让我了解我做错了什么,我将不胜感激。谢谢!