Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include <time.h>
- int main(void)//主程式
- {
- FILE *read;
- read = fopen("score.txt","r");
- int i,j;
- int string[50];
- int count, sum;
- float avg, degree[20];//avg放平均分數,degree[變數]=1為不及格, degree[變數]=0為及格
- count = 0;
- ///////////////////////陣列歸零//////////////////////////////////////////////////
- for (i=1; i<=20; i++)
- degree[i]=0;
- /////////////////////讀成績檔////////////////////////////////////////////
- printf("\n**讀成績檔**\n\n");
- while(! feof(read) ){
- fscanf(read, "%d %d %d %d %d %d %d %d %d %d\r\n", &string[1],&string[2],&string[3],&string[4],&string[5],&string[6],&string[7],&string[8],&string[9],&string[10]);
- sum=0;
- for (i=1; i<=10; i++)
- {
- sum = sum + string[i];
- printf("%d ",string[i]);
- }
- count = count + 1;
- avg = (float)sum/10;
- if (avg<60)//將不及格的挑出
- degree[count]=1;
- printf(" 平均:%.2f",(float)sum/10);
- printf("\n===============================================================\n\n");
- }
- fclose(read);
- ////////////////////讀檔,若degree[count]=1則印出來/////////////////////////////////////////
- printf("**讀檔**\n");
- char str[100];
- int b,num;
- read = fopen("student.txt","r");
- count=1;
- printf("不及格的有:\n");
- while (fgets (str, 65535, read))
- {
- if (degree[count]==1)
- {
- printf("%s",str);
- }
- count=count+1;
- }
- fclose(read);
- /////////////////////////////////////////////////////////////////////////////////////////
- printf("\n=====================\n\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement