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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

錯誤在哪,怎么改呢?

錯誤在哪,怎么改呢?

C
賈俊蕊 2016-03-04 10:46:27
#include <stdio.h>int ZongScore(){?int i;??? int sum=0;??? for(i=0;i<10;i++)??? {? ? ?int score[];??sum=sum+score[i]; ??? }??? printf("考試的總分是%d",sum);??? return 0;}int HighScore(){??? int i;??? score=score[0];??? for(i=0;i<10;i++)??? {??????? if(score<score[i])??????? {??????????? score=score[i];??????? }??? }??? printf("考試的最高分是%d",score);??? return 0;}int LowScore(){?? int i;??? score=score[0];??? for(i=0;i<10;i++)??? {??????? if(score>score[i])??????? {??????????? score=score[i];??????? }??? }??? printf("考試的最低分是%d",score);??? return 0; }int PingScore(){??? int ZongScore;??? score=score/10;??? printf("考試的平均分是%d",score);??? return 0;}int PAIScore(){??? int i,j;??? for(i=8;i>=0;i--)??? {??????? for(j=0;j<=i;j++)??????? {??????????? if(score[j]<score[j+1])??????????? {??????????????? int score;??????????????? score=score[j];??????????????? score[j]=score[j+1];??????????????? score[j+1]=score;??????????? }??????? }??? }??? print("考試成績降序排列\n");??? for(i=0;i<10;i++)??? {??????? if(i != 9)??????? printf("%d,",score[i]);??????? else??? ??????? printf("%d",score[i]);??? }??? return 0;}int main(){??? int score[N]={67,98,75,63,82,79,81,91,66,84};??? ZongScore();??? HighScore();??? LowScore();??? PingScore();??? PAIScore();??? return 0;}
查看完整描述

1 回答

已采納
?
計量趙子龍

TA貢獻9條經驗 獲得超14個贊

這是我修改后的代碼,以及運行結果

http://img1.sycdn.imooc.com/56d93b8e0001fb5d06720440.jpg

  1. #include <stdio.h>

  2. #define N 10

  3. int ZongScore(int score[])

  4. {

  5. ? ? int i;

  6. ? ? int sum=0;

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

  8. ? ? {

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

  10. ? ? }

  11. ? ? printf("考試的總分是%d\n",sum);

  12. }

  13. int HighScore(int score[])

  14. {

  15. ? ? int i;

  16. ? ? int HighScore=score[0];

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

  18. ? ? {

  19. ? ? ? ? if(HighScore<score[i])

  20. ? ? ? ? {

  21. ? ? ? ? ? ? HighScore=score[i];

  22. ? ? ? ? }

  23. ? ? }

  24. ? ? printf("考試的最高分是%d\n",HighScore);


  25. }

  26. int LowScore(int score[])

  27. {

  28. ? ?int i;

  29. ? ?int LowScore=score[0];

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

  31. ? ? {

  32. ? ? ? ? if(LowScore>score[i])

  33. ? ? ? ? {

  34. ? ? ? ? ? ? LowScore=score[i];

  35. ? ? ? ? }

  36. ? ? }

  37. ? ? printf("考試的最低分是%d\n",LowScore);

  38. }

  39. int PingScore(int score[])

  40. {

  41. ? ? int i,ZongScore=0;

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

  43. ? ? ? ? ZongScore+=score[i];

  44. ? ? int PJscore=ZongScore/N;

  45. ? ? printf("考試的平均分是%d\n",PJscore);

  46. }

  47. int PAIScore(int score[])

  48. {

  49. ? ? int i,j;

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

  51. ? ? {

  52. ? ? ? ? for(j=0;j<N-i-1;j++)

  53. ? ? ? ? {

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

  55. ? ? ? ? ? ? {

  56. ? ? ? ? ? ? ? ? int temp;

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

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

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

  60. ? ? ? ? ? ? }

  61. ? ? ? ? }

  62. ? ? }

  63. ? ? printf("考試成績降序排列\n");

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

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

  66. }

  67. int main()

  68. {

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

  70. ? ? ZongScore(score);

  71. ? ? HighScore(score);

  72. ? ? LowScore(score);

  73. ? ? PingScore(score);

  74. ? ? PAIScore(score);

  75. ? ? return 0;

  76. }

感覺你應該注意一下幾點:

1.注意使用define宏定義,提高代碼的靈活性;

2.注意函數的定義,要賦給函數正確的參數;不要隨意使用return 0,這是用來結束程序的,如果你第一個函數最后就用return 0,那后面的函數不會執行,也就失去了定義和使用的價值;

3.正確使用冒泡排序,這個經典的排序方法實際用途很廣發,計算機考級也可以說是必考的。

初學C還是要不怕困難多多練習,希望你在今后學習的路上不斷提高,受益匪淺。


查看完整回答
2 反對 回復 2016-03-04
  • 1 回答
  • 0 關注
  • 1396 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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