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

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

代碼答案哦 (借鑒)

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define N 10

int main()

{

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

? ? float sum, max_score, min_score, avg;

? ? int i, j, temp;

? ? //計算考試總分

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

? ? {

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

? ? }

? ? printf("考試總分為:%.2f\n",sum);

? ? printf("*********************************\n");

? ? //計算考試平均分

? ? avg = sum / N;

? ? printf("考試平均分為:%.2f\n",avg);

? ? printf("*********************************\n");

? ? //考試成績降序排序

? ? for(i = N - 1; i > 0; i--)

? ? {

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

? ? ? ? {

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

? ? ? ? ? ? {

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

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

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

? ? ? ? ? ? }

? ? ? ? }

? ? }

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

? ? {

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

? ? }

? ? printf("\n");

? ? printf("*********************************\n");

? ? //查詢最高分

? ? max_score = 0;

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

? ? {

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

? ? ? ? {

? ? ? ? ? ? max_score = score[i];

? ? ? ? }

? ? }

? ? printf("最高分為:%.2f\n",max_score);

? ? printf("*********************************\n");

? ? //查詢最低分

? ? min_score = 100;

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

? ? {

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

? ? ? ? {

? ? ? ? ? ? min_score = score[i];

? ? ? ? }

? ? }

? ? printf("最高分為:%.2f\n",min_score);

? ? printf("*********************************\n");

? ? return 0;

}

總分:786.00

平均分:78.60

降序排列:98? 91? 84? 82? 81? 79? 75? 66? 63

最高:98.00

最低:63.00(目前還不會用函數)


正在回答

1 回答

#include <stdio.h>

# define N 10


int sum(int score[])

{

? ? int i,sum=0;

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

? ??

? ? {

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

? ? }

? ? return sum;

}

int high(int score[])

{

? ? int i,high=score[0];

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

? ? {

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

? ? ? ? high=score[i];

? ? }

? ? return high;

}

int low( int score[])

{

? ? int i,low=score[0];

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

? ? {

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

? ? ? ? low=score[i];

? ? }

? ? return low;

}

float ave(int score[])

{

? ? float ave=(float)(sum(score))/N;

return ave;

}

void xu(int score[])

{

int i,j;

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

? ? {

? ? ? ? for(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;

? ? ? ? ? ? ? ? }

? ? ? ? }

? ? }

printf("降序為");

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

{

if(i==9)

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

else

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

? ?}

}

int main()

{

? ??

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

? ? printf("總分為%d\n",sum(score));

? ? printf("最高分為%d\n",high(score));

? ? printf("最低分為%d\n",low(score));

? ? printf("平均分為%f\n",ave(score));

? ? xu(score);

? ? return 0;

}

?有大佬瞅瞅有什么不規范還可以改的咩。。。。。 (小聲說)

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

舉報

0/150
提交
取消
C語言入門
  • 參與學習       926904    人
  • 解答問題       21532    個

C語言入門視頻教程,帶你進入編程世界的必修課-C語言

進入課程

代碼答案哦 (借鑒)

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

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

幫助反饋 APP下載

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

公眾號

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