這是代碼:
#include <stdio.h>
int main(){
int i, j;
float average;
int grades[5][2] = {
{40, 45},
{37, 40},
{43, 49},
{33, 39},
{46, 45}
};
printf("Let's calculate the average of the marks obtained by the students "
"in the two subjects.\n\n");
for(j = 0; j < 5; j ){
average = 0;
for(i = 0; i < 2; i ){
average = grades[j][i];
}
printf("The average mark scored by the student %d is -> %.2f out of 50 \n", j, average/2);
}
}
它給出的輸出為:'學生得分的平均分(j 的索引)是'
我將如何讓它輸出不同學生的名字?例如 - '學生 John 的平均分數是'。
uj5u.com熱心網友回復:
假設您有一個包含學生姓名的字串陣列:
...
for(j = 0; j < 5; j ){
average = 0;
for(i = 0; i < 2; i ){
average = grades[j][i];
}
printf("The average mark scored by the student %s is -> %.2f out of 50 \n", student_names[j], average/2);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/448874.html
標籤:C
