stdout给出:
---------------------------------------- ----------
以下是所有3名学生的成绩。
--------------------------------- -----------------
虽然我希望它显示:
----------------------------------- ---------------
以下是所有3名学生的成绩:
- > 8.75
- > 9.25
- > 9.00
--------------------------------------------- -----
这是代码:
#include <stdio.h>
int main(void) {
/*The grades of 3 students*/
int grades[3][4] = {{ 7,10,9,9 }, { 10,10,8,9 }, { 9,8,9,10 } };
float result1 = (grades[0][0] + grades[0][1] + grades[0][2] + grades[0][3])/4;
float result2 = (grades[1][0] + grades[1][1] + grades[1][2] + grades[1][3])/4;
float result3 = (grades[2][0] + grades[2][1] + grades[2][2] + grades[2][3])/4;
printf("Here are the results of all 3 students:\n");
/*I stored the results into an array so i can use for loop to display them faster*/
float a[3]= {result1,result2,result3};
/*Here i wanted to try to display the results using for loop*/
int i;
for (i = 0; i > 3; i++){
printf(" --> %.2f\n", a[i]);
}
return 0;
}
输出有什么问题?
答案 0 :(得分:2)
问题在于:
for (i = 0; i > 3; i++)
尝试for (i = 0; i < 3; i++)
(i
小于3,而i
大而不是3,这绝不是......)