任务:
int marks[10], sum = 0, range[5];
printf("Enter the survey marks for the 10 questions:\n");
for (int i = 0; i < 10; i++){
scanf("%d", &marks[i]);
sum += marks[i];
if (marks[i] == 0){
range[0] += 1;
}
else if (marks[i] == 1){
range[1] += 1;
}
else if (marks[i] == 2){
range[2] += 1;
}
else if (marks[i] == 3){
range[3] += 1;
}
else{
range[4] += 1;
}
}
printf("Response\tfrequency\n");
printf("--------\t---------\n");
printf("0-Very Bad\t%5d\n", range[0]);
printf("1-Bad\t\t%5d\n", range[1]);
printf("2-Good\t\t%5d\n", range[2]);
printf("3-Very Good\t%5d\n", range[3]);
printf("4-Excellent\t%5d\n\n", range[4]);
printf("Total mark = %d\n", sum);
答案 0 :(得分:1)
呃,只需要将我的范围初始化为0。
range[5] = { 0 }
之后工作 lol 。
答案 1 :(得分:0)
将数组的所有元素初始化为零。你有数组中的垃圾值。 像这样: -
int range[5]={0,0,0,0,0};