Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. FILE *inp,*out;
  6.  
  7. int status,r=0,c=0,stu_id,size;
  8. double quiz[50][5],sum_stu=0,sum_quiz = 0;
  9.  
  10. inp = fopen("grades.txt","r");
  11.  
  12. if(inp == NULL) printf("YUUH");
  13.  
  14. else{
  15. out = fopen("average.txt","w");
  16.  
  17. status = fscanf(inp,"%d",&stu_id);
  18.  
  19. while(status != EOF)
  20. {
  21. for(c =0; c<5; c++)
  22. {
  23. fscanf(inp,"%lf",&quiz[r][c]);
  24. sum_stu += quiz[r][c];
  25.  
  26. }//for
  27. fprintf(out,"%d %.1f\n",stu_id, sum_stu/5);
  28. r++;
  29.  
  30. status = fscanf(inp,"%d",&stu_id);
  31. }//while
  32.  
  33. size = r;
  34.  
  35. printf("Quiz Number Average\n");
  36. for(c = 0; c<5; c++){
  37. for(r = 0; r<size; r++){
  38. sum_quiz += quiz[r][c];
  39. }
  40. printf("%d %.2f\n", c+1, sum_quiz/size);
  41.  
  42. }//for
  43.  
  44.  
  45.  
  46. }//else
  47.  
  48. fclose(inp);
  49. fclose(out);
  50. return(0);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement