fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct Student Student;
  4. int mark(Student*);
  5.  
  6. #define BUFSIZE 256
  7. #define BALLS 5
  8. #define MAXMARK 5
  9.  
  10. struct Student
  11. {
  12. char fullname[BUFSIZE];
  13. char subject[BUFSIZE];
  14. int balls[BALLS];
  15. int maxball;
  16. };
  17.  
  18. double
  19. avgball(Student *s)
  20. {
  21. int i;
  22. double ball;
  23.  
  24. ball = 0.0;
  25. for (i = 0; i < BALLS; i++)
  26. ball += s->balls[i];
  27. return ball / BALLS;
  28. }
  29.  
  30. int
  31. mark(Student *s)
  32. {
  33. return avgball(s) * MAXMARK / s->maxball;
  34. }
  35.  
  36. int
  37. main(void)
  38. {
  39. Student s;
  40. s.balls[0] = 64;
  41. s.balls[1] = 83;
  42. s.balls[2] = 95;
  43. s.balls[3] = 51;
  44. s.balls[4] = 72;
  45. s.maxball = 100;
  46. printf("%d\n", mark(&s));
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
3