我不明白这一行:marks_count[total_marks[i]]++;
。请描述其含义。
int i;
int total_marks[] = {86, 78, 94, 68, 92, 78, 64, 62, 72, 61, 72, 66, 65, 65, 80, 72, 62, 68, 81, 62, 56, 68, 58, 56, 82, 70, 74, 78, 76, 84, 88, 73, 62, 66, 76, 70, 67, 65, 77, 63};
int marks_count[101];
for(i = 0; i < 101; i++) {
marks_count[i] = 0;
}
for(i = 0; i < 40; i++) {
marks_count[total_marks[i]]++;
}
for(i = 50; i <= 100; i++) {
printf("Marks: %d Count: %d\n", i, marks_count[i]);
}
最佳答案
total_marks
数组保存人们在测试中获得的所有分数(当然,假设这是一个测试)。
什么:
marks_count[total_marks[i]]++;
的作用是增加与某人获得的标记相对应的数组元素。换句话说,就是计算每个标记的结果数。
更多详细信息:
// Initialise all counts to zero.
for(i = 0; i < 101; i++) {
marks_count[i] = 0;
}
// For each of forty results, increment the
// count corresponding to the result.
for(i = 0; i < 40; i++) {
marks_count[total_marks[i]]++;
}
例如,如果数组只是{42, 7, 42}
(并且大小更正为三而不是四十),那么您最终会得到一个大部分为零的数组,除了:
marks_count[7] = 1
marks_count[42] = 2
关于c - 我不明白这一行,marks_count[total_marks[i]]++;请任何人描述一下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53738226/