1 回答

TA貢獻9條經驗 獲得超14個贊
這是我修改后的代碼,以及運行結果
#include <stdio.h>
#define N 10
int ZongScore(int score[])
{
? ? int i;
? ? int sum=0;
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? sum=sum + score[i];
? ? }
? ? printf("考試的總分是%d\n",sum);
}
int HighScore(int score[])
{
? ? int i;
? ? int HighScore=score[0];
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? if(HighScore<score[i])
? ? ? ? {
? ? ? ? ? ? HighScore=score[i];
? ? ? ? }
? ? }
? ? printf("考試的最高分是%d\n",HighScore);
}
int LowScore(int score[])
{
? ?int i;
? ?int LowScore=score[0];
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? if(LowScore>score[i])
? ? ? ? {
? ? ? ? ? ? LowScore=score[i];
? ? ? ? }
? ? }
? ? printf("考試的最低分是%d\n",LowScore);
}
int PingScore(int score[])
{
? ? int i,ZongScore=0;
? ? for(i = 0 ;i < N; i ++)
? ? ? ? ZongScore+=score[i];
? ? int PJscore=ZongScore/N;
? ? printf("考試的平均分是%d\n",PJscore);
}
int PAIScore(int score[])
{
? ? int i,j;
? ? for(i=0;i<N;i++)
? ? {
? ? ? ? for(j=0;j<N-i-1;j++)
? ? ? ? {
? ? ? ? ? ? if(score[j]<score[j+1])
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int temp;
? ? ? ? ? ? ? ? temp=score[j];
? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? score[j+1]=temp;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? printf("考試成績降序排列\n");
? ? for(i=0;i<N;i++)
? ? ? ? printf("%d,",score[i]);
}
int main()
{
? ? int score[N]={67,98,75,63,82,79,81,91,66,84};
? ? ZongScore(score);
? ? HighScore(score);
? ? LowScore(score);
? ? PingScore(score);
? ? PAIScore(score);
? ? return 0;
}
感覺你應該注意一下幾點:
1.注意使用define宏定義,提高代碼的靈活性;
2.注意函數的定義,要賦給函數正確的參數;不要隨意使用return 0,這是用來結束程序的,如果你第一個函數最后就用return 0,那后面的函數不會執行,也就失去了定義和使用的價值;
3.正確使用冒泡排序,這個經典的排序方法實際用途很廣發,計算機考級也可以說是必考的。
初學C還是要不怕困難多多練習,希望你在今后學習的路上不斷提高,受益匪淺。
- 1 回答
- 0 關注
- 1396 瀏覽
添加回答
舉報