亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請問一下我這個哪里有問題?

#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;

}


正在回答

3 回答

sort 里面的?if(score[i]<score[i+1])? ?如果i是9 的話,i+1就是10? 數組越界了

0 回復 有任何疑惑可以回復我~

前面加個#define N 10

0 回復 有任何疑惑可以回復我~

未定義N=10

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

請問一下我這個哪里有問題?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號