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

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

求解答啊 不知道哪錯了 運行不出來

#include <stdio.h>

int main()

{

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

? ? int total = fun1(score);

? ? int max = fun2(score);

? ? int min = fun4(score);

? ? int average = total/10;

? ? fun3(score);

? ? printf("%d",max);

? ? printf("%d",min);

? ? printf("%d",total);

? ? printf("%d",average);

? ? return 0;

}


int fun1(int score[]){

? ? int total = 0;

? ? for(int i=0;i<10;i++){

? ? ? ? total += score[i];

? ? }

? ? return total;

}


int fun2(int score[]){

? ? int max;

? ? for(int i=0;i<9;i++){

? ? ? ? if(score[i]>max){

? ? ? ? ? ? max = score[i];

? ? ? ? }

? ? }

? ? return max;

}


int fun4(int score[]){

? ? int min;

? ? for(int i=0;i<9;i++){

? ? ? ? if(score[i]<min){

? ? ? ? ? ? min = score[i];

? ? ? ? }

? ? }

? ? return min;

}


void fun3(int score[]){

? ? for(int i=8;i>=0;i--){

? ? ? ? for(int j=0;j<=i;j++){

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

? ? ? ? ? ? ? ? int temp;

? ? ? ? ? ? ? ? temp=score[j];

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

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

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? for(int i=0;i<10;i++){

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

? ? }

}


正在回答

3 回答

求最大值、最小值等幾個函數判斷循環結束的條件應該為i<10或i<=9

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

必須先聲明函數,然后才能調用函數,而且數組里的N是不用加的,放在編譯器里是錯誤的,因為N并未聲明,慕課網的代碼運行有一點問題,換成下邊在編譯器運行是可以的,希望可以幫助到你。


#include <stdio.h>

int fun1(int score[]){

? ? int total = 0;

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

? ? {

? ? ? ? total += score[i];

? ? }

? ? return total;

}

int fun2(int score[]){

int max=score[0];

? ? for(int i=0;i<9;i++)

? ? {

? ? ? ? if(score[i]>max)

? ? ? ? {

? ? ? ? ? ? max = score[i];

? ? ? ? }

? ? }

? ? return max;

}

int fun4(int score[]){

? ? int min=score[0];

? ? for(int i=0;i<9;i++){

? ? ? ? if(score[i]<min){

? ? ? ? ? ? min = score[i];

? ? ? ? }

? ? }

? ? return min;

}

void fun3(int score[]){

? ? for(int i=8;i>=0;i--){

? ? ? ? for(int j=0;j<=i;j++){

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

? ? ? ? ? ? ? ? int temp;

? ? ? ? ? ? ? ? temp=score[j];

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


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

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? for(int i=0;i<10;i++){

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

? ? }

? ? printf("\n");

}

int main()

{??

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

? ? int total = fun1(score);

? ? int max = fun2(score);

? ? int min = fun4(score);

? ? int average = total/10;

? ? fun3(score);

? ? printf("%d\n",max);

? ? printf("%d\n",min);

? ? printf("%d\n",total);

? ? printf("%d\n",average);

? ? return 0;

}


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

除了循環條件外,還有在函數實現的時候int score[N]是不對的,改成int score[]就好了

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

舉報

0/150
提交
取消

求解答啊 不知道哪錯了 運行不出來

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

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

幫助反饋 APP下載

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

公眾號

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