点击(此处)折叠或打开
- #include <stdio.h>
- #define ANSWER_SIZE 20 /* The number of the answer */
- #define STATISTICS_SIZE 10 /* The kinds of the answer */
- int main(){
- int i_answer[] = { 2, 3, 4, 6, 7, 6, 10, 4, 8, 2, 2, 3, 9, 6, 9, 6, 10, 4, 8, 9 }; /* initialize the answer array */
- int i_statistics[STATISTICS_SIZE] = { 0 }; /* initialize the statistics array "0" */
-
- for (size_t i = 0; i <= (ANSWER_SIZE-1); i++){
- i_statistics[ i_answer[i]-1 ]++; /* traverse the answer array,
- the element value corresponding the statistics array`s subscript,
- and the relevant value +1 */
- }
- /* output the result */
- printf("%s%17s\n", "Grade", "Statistics");
- for (size_t i = 0; i <= (STATISTICS_SIZE-1); i++){
- printf("%d%17d\n", (i+1), i_statistics[i]);
- }
-
- return 0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议