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

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

為什么算不出結果?

#include <stdio.h>
int main()
{
??? int score[]={67,98,75,63,82,79,81,91,66,84};
??? int sum;
??? int max=score[0];
??? int min=score[0];
??? int i,j;
??? for(i=0;i<10;i++)
??? {
??????? sum+=score[i];
??????? if(score[i]>=max)
??????? {
??????????? max=score[i];
??????? }
??????? else if(score[i]<min)
??????? {
??????????? min=score[i];
??????? }
??? }
??? printf("計算考試的總分為:%d\n",sum);
??? printf("計算考試的最高分為:%d\n",max);
??? printf("計算考試的最低分為:%d\n",min);
??? double averge=sum/10.0;
??? printf("計算考試的平均分為:%.1f\n",averge);
??? for(i=8;i>=0;i--)
??? {
??????? for(j=0;j<=i;j)
??????? {
??????????? if(score[j]<score[j+1])
??????????? {
??????????????? int temp;
??????????????? temp=score[j+1];
??????????????? score[j+1]=score[j];
??????????????? score[j]=temp;
??????????? }
??????? }
??? }
??? printf("計算考試的降序排序為:");
??? for(i=0;i<10;i++)
??? {
??????? if(i==9)
??????? {
??????????? printf("%d",score[i]);
??????? }
??????? else
??????? {
??????????? printf("%d, ",score[i]);
??????? }
??? }
??? return 0;
}

正在回答

2 回答

第三個for語句:???

for(i=8;i>=0;i--)
??? {
??????? for(j=0;j<=i;j); 這里你沒有j++。你的程序也就沒有完成降序而已,就是這里的細節出了問題。你試試改這里就好了,我已經驗證成功了。
???

?

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

lzj1136667251 提問者

好了,謝謝,找了好久
2018-10-11 回復 有任何疑惑可以回復我~

#include <stdio.h>

int main()

{

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

? ??

? ??

? ? int sum(int score[])

? ? {

? ? ? ? int sum;

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

? ? ? ? {

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

? ? ? ? ? ??

? ? ? ? }

? ? ? ??

? ? ? ? return sum;

? ? }

? ??

? ? int topScore(int score[])

? ? {

? ? ? ? int top = 0;

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

? ? ? ? {

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

? ? ? ? ? ? top = score[i];

? ? ? ? }

? ? ? ? return top;

? ? }

? ??

? ? int bottomScore(int score[])

? ? {

? ? ? ? int bottom = 100;

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

? ? ? ? {

? ? ? ? ? ? if(score[i]<bottom)

? ? ? ? ? ? bottom = score[i];

? ? ? ? }

? ? ? ? return bottom;

? ? }

? ??

? ? int average(int score[])

? ? {

? ? ? ? int i;

? ? ? ? int sum = 0;

? ? ? ??

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

? ? ? ? {

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

? ? ? ? }

? ? ? ??

? ? ? ? return sum/i;

? ? }

? ??

? ? void bubble_sort(int arr[],int n)

? ? {

? ? ? ? int temp;

? ? ? ? for(int i=n-1; i>0; i--)

? ? ? ? {

? ? ? ? ? ? for(int j=n-1; j>0; j--)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(arr[j] > arr[j-1])

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? temp = arr[j];

? ? ? ? ? ? ? ? ? ? arr[j] = arr[j-1];

? ? ? ? ? ? ? ? ? ? arr[j-1] = temp;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ??

? ??

? ? printf("sum=%d\n",sum(score));

? ? printf("topScore=%d\n",topScore(score));

? ? printf("bottomScore=%d\n",bottomScore(score));

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

? ??

? ? printf("***********排序后********\n");

? ??

? ? bubble_sort(score,10);

? ??

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

? ? {

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

? ? }

? ??

? ? return 0;

? ??

}


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

舉報

0/150
提交
取消

為什么算不出結果?

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

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

幫助反饋 APP下載

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

公眾號

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