Advertisement
kk258966

10/3 進階程式設計 練習三

Oct 3rd, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6. FILE *read;
  7. read = fopen("score.txt","r");
  8. int i,j;
  9. int string[50];
  10. int count,sum;
  11. float avg[20],tmp;
  12. count=0;
  13.  
  14. printf("\n**讀成績檔**\n\n");
  15. while(!feof(read))
  16.     {
  17.                    sum=0;
  18.                    for(i=1; i<=10; i++)
  19.                    {
  20.                      fscanf(read, "%d",&string[i]);
  21.                      sum=sum+string[i];
  22.                      printf(" %d",string[i]);
  23.                    }                  
  24.                      count=count+1;
  25.                      avg[count]=(float)sum/10;
  26.                      
  27.                      printf("    平均:%.2f",(float)sum/10);
  28.                      printf("\n====================================================\n");
  29.     }
  30. fclose(read);
  31.    printf("****************排序***************\n\n");
  32.    for(i=1;i<count;i++)
  33.    {
  34.                        for(j=i+1;j<count;j++)
  35.                        {
  36.                                              if(avg[i]>avg[j])
  37.                                              {
  38.                                                               tmp=avg[j];
  39.                                                               avg[j]=avg[i];
  40.                                                               avg[i]=tmp;
  41.                                              }
  42.                        }
  43.    }
  44. printf("****************排序完成***************\n\n");
  45.     for(i=1;i<count;i++)
  46.     printf("%.2f,",avg[i]);
  47.    
  48.    
  49.     system("pause");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement