运行成功出结果,但是报方法错误,有哪位看得懂怎么改吗? 附上我的代码和运行结果
#include <stdio.h>
int main()
{
int score[10]={67,98,75,63,82,79,81,91,66,84};
getTotalScore(score);
getMaxScore(score);
getMinScore(score);
getAverageScore(score);
sort(score);
return 0;
}
//总分
int getTotalScore(int score[]) {
int sum = 0;
for(int i=0; i<10; i++) {
sum += score[i];
}
printf("总分为%d\n", sum);
return sum;
}
//最高分
int getMaxScore(int score[]) {
int max = 0;
int tmp = 0
for(int i=9; i>0; i--) {
for(int j=0; j<i; j++) {
if(score[j]>score[j+1]) {
tmp = score[j];
score[j] = score[j+1];
score[j+1] = tmp;
}
}
}
max = score[9];
printf("最高分为%d\n", max);
return max;
}
//最低分
int getMinScore(int score[]) {
int min = 0;
int tmp = 0;
//写法一:
/*for(int i=0; i<10; i++) {
for(int j=0; j<9; j++) {
if(score[j]>score[j+1]) {
tmp = score[j];
score[j] = score[j+1];
score[j+1] = tmp;
}
}
}*/
//写法二:
for(int i=9; i>0; i--) {
for(int j=0; j<i; j++) {
if(score[j]>score[j+1]) {
tmp = score[j];
score[j] = score[j+1];
score[j+1] = tmp;
}
}
}
min = score[0];
printf("最低分为%d\n", min);
return min;
}
//平均分
int getAverageScore(int score[]) {
int averageScore = 0;
int sum = 0;
for(int i=0; i<10; i++) {
sum += score[i];
}
averageScore = (sum / 10);
printf("平均分分为%d\n", averageScore);
return averageScore;
}
//降序排序
int sort(int score[]) {
int tmp = 0;
//执行排序 升序
for(int i=9; i>0; i--) {
for(int j=0; j<i; j++) {
if(score[j]>score[j+1]) {
tmp = score[j];
score[j] = score[j+1];
score[j+1] = tmp;
}
}
}
//打印排序结果 从后面的数开始打印
printf("考试成绩降序排列:");
for(int i=9; i>=0; i--) {
printf("%d\t", score[i]);
}
return 0;
}
运行成功
hello.c: In function 'main':
hello.c:6:5: warning: implicit declaration of function 'getTotalScore' [-Wimplicit-function-declaration]
getTotalScore(score);
^~~~~~~~~~~~~
hello.c:7:5: warning: implicit declaration of function 'getMaxScore' [-Wimplicit-function-declaration]
getMaxScore(score);
^~~~~~~~~~~
hello.c:8:5: warning: implicit declaration of function 'getMinScore' [-Wimplicit-function-declaration]
getMinScore(score);
^~~~~~~~~~~
hello.c:9:5: warning: implicit declaration of function 'getAverageScore' [-Wimplicit-function-declaration]
getAverageScore(score);
^~~~~~~~~~~~~~~
hello.c:10:5: warning: implicit declaration of function 'sort' [-Wimplicit-function-declaration]
sort(score);
^~~~
总分为786
最高分为98
最低分为63
平均分分为78
考试成绩降序排列:98 91 84 82 81 79 75 67 66 63