Advertisement
kk258966

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

Oct 17th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 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,degree[20];  //avg放平均分數,degree[變數]=1為不及格0
  12.     count=0;
  13.    
  14.    
  15.     ////////////////////陣列歸零//////////////////////////
  16.    
  17.     for (i=0;i<=19;i++)
  18.     degree[i]=0;
  19.    
  20.     //////////////////讀成績檔////////////////////////
  21.    
  22.     printf("\n**讀成績檔**\n\n");
  23.     while(!feof(read))
  24.     {
  25.       for(i=1;i<=10;i++)
  26.       fscanf(read,"%d",&string[i]);
  27.       sum=0;
  28.       for(i=1;i<=10;i++)
  29.       {
  30.          sum=sum+string[i];
  31.          printf("%d ",string[i]);
  32.       }
  33.      
  34.       avg=(float)sum/10;
  35.       if(avg<60)   //將不及格挑出
  36.        degree[count]=1;
  37.        
  38.        printf("   平均:%.2f", (float)sum/10);
  39.        printf("\n===========================================\n");
  40.        count++;              
  41.     }
  42.      fclose(read);
  43.    
  44.    
  45.     ////////////讀檔,若degree[count]=1則印出來//////////////
  46.    
  47.     printf("**讀檔**\n");
  48.     char str[100];
  49.     int b,num;
  50.     read=fopen("student.txt","r");
  51.     count=1;
  52.     printf("不及格的有:\n");
  53.     while(fgets(str,65535,read))
  54.     {
  55.       if(degree[count]==1)
  56.       {
  57.          printf("%s",str);                
  58.       }                  
  59.       count++;      
  60.     }
  61.     fclose(read);
  62.    
  63.      printf("\n===========================================\n");
  64.    
  65.      
  66.     system("pause");
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement