求大神解答 我的代码哪里出粗了

#include <stdio.h>

int SumAverage()

{

int score[10] = { 67, 98, 75, 63, 82, 79, 91, 66, 84 };

int i;

int sum = 0;

int average;

for (i = 0; i < 10; i++)

{

sum = sum + score[i];

average = sum / 10;

}

printf("考试的总分是:%d", sum);

printf("考试平均分是:%d", average);

return 0;

}int paixuchengji()

{

int score[10] = { 67, 98, 75, 63, 82, 91, 66, 84 };

int i;

int j;

int temp;

for (i = 8; i >= 0; i--)

{

for (j = 0; j <=i; j++)

{

if (score[j] < score[j + 1])

{

temp = score[j];

score[j] = score[j + 1];

score[j + 1] = temp;

}

}

}

printf("\n成绩降序排序为:\n");

for (i = 0; i < 10; i++)

{

if (i != 9)

printf("%d\n", score[i]);

else

printf("%d\n", score[i]);

}

printf("考试成绩的最高分是:%d", score[0]);

printf("考试的最低成绩是:%d\n", score[9]);

}

int main()

{

SumAverage();

paixuchengji();

return 0;

}






考试的总分是:705考试平均分是:70

成绩降序排序为:

98

91

84

82

75

67

66

63

0

0

考试成绩的最高分是:98考试的最低成绩是:0

请按任意键继续. . .

这是运行后的结果 

叫我健哥就行
浏览 1812回答 2
2回答

RockenRoll

你的数组定义的有问题,int score[10] = { 67, 98, 75, 63, 82, 79, 91, 66, 84 };这里面只有9个元素,但是你创建的是一个长度为10的数组,所以最后一个元素会默认是0.for (i = 8; i >= 0; i--)把i的初值设置为9。if (i != 9) printf("%d\n", score[i]); else printf("%d\n", score[i]);这个代码放这没起到效果,直接printf("%d\n", score[i]);就可以了

慕移动9341187

#include <stdio.h>int SumAverage(){int score[11] = { 67, 98, 75, 63, 82, 79, 91, 66, 84 ,65,99};int i;int sum = 0;int average;for (i = 0; i <11; i++){sum = sum + score[i];average = sum / 10;}printf("考试的总分是:%d", sum);printf("考试平均分是:%d", average);return 0;}int paixuchengji(){int score[11] = { 67, 98, 75, 63, 82, 91, 66, 84 ,65,99};int i;int j;int temp;for (i = 8; i >= 0; i--){for (j = 0; j <=i; j++){if (score[j] < score[j + 1]){temp = score[j];score[j] = score[j + 1];score[j + 1] = temp;}}}printf("\n成绩降序排序为:\n");for (i = 0; i < 10; i++){if (i != 9)printf("%d\n", score[i]);elseprintf("%d\n", score[i]);}printf("考试成绩的最高分是:%d", score[0]);printf("考试的最低成绩是:%d\n", score[9]);}int main(){SumAverage();paixuchengji();return 0;}看加粗,倾斜部分,按照那样修改就行了.
打开App,查看更多内容
随时随地看视频慕课网APP