請問一下我這個哪里有問題?
#include <stdio.h>
int N;
int totalsc(int score[]){
? ? int i,total;
? ? for(i=0;i<N;i++){
? ? ? ? total+=score[i];
? ? }
? ? return total;
}
int maxsc(int score[]){
? ? int i,max;
? ? max=score[0];
? ? for(i=0;i<N;i++){
? ? ? ? if(score[i]>max)
? ? ? max=score[i];
? ? }
? ? return max;
}
int minsc(int score[]){
? ? int i,min;
? ? min=score[0];
? ? for(i=0;i<N;i++){
? ? ? ? if(score[i]<min)
? ? ? min=score[i];
? ? }
? ? return min;
}
int avgsc(int score[]){
? ?int i,total,avg;
? ? for(i=0;i<N;i++){
? ? ? ? total+=score[i];
? ? }?
? ? avg=total/N;
? ? return avg;
}
int sort(int score[]){
? ? int i,temp;
? ? for(i=0;i<N;i++){
? ? ? ? if(score[i]<score[i+1])
? ? ? ? temp=score[i+1];
? ? ? ? score[i+1]=score[i];
? ? ? ? score[i]=temp;
? ? }
? ? return score[i];
? ? printf("考試排名%d",score[i]);
}
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ?int min,max,avg,total;
? ?N=10;
? ?min=minsc(score);
? ?max=maxsc(score);
? ?avg=avgsc(score);
? ?total=totalsc(score);
? ? printf("總分為:%d",total);
? ? printf("最高分%d,最低分%d,平均分%d",max,min,avg);
? ? sort(score);
? ??
? ? return 0;
}
2020-06-15
sort 里面的?if(score[i]<score[i+1])? ?如果i是9 的話,i+1就是10? 數組越界了
2020-06-02
前面加個#define N 10
2020-05-26
未定義N=10