Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. #define MAX_SIZE 50
  6.  
  7.  
  8.  
  9.  
  10. typedef struct athletesID{
  11. char name[MAX_SIZE+1];
  12. int points;
  13. float playtime;
  14. } Athlete;
  15.  
  16.  
  17. void readAthlete (Athlete *athletes, int n);
  18. float computeMAX (Athlete *athletes, int n);
  19. void printAthlete(Athlete *athletes, float MAX, int n);
  20. int main()
  21. {
  22. int numA;
  23. float MAX;
  24. Athlete *athletes;
  25. printf("Enter the number of athletes. \n");
  26. scanf("%d", &numA);
  27. getchar();
  28. athletes = (Athlete*)malloc(sizeof(Athlete)*numA);
  29.  
  30. readAthlete (athletes, numA);
  31. computeMAX (athletes, numA);
  32. printAthlete(athletes, MAX, numA);
  33.  
  34. free(athletes);
  35. return 0;
  36. }
  37.  
  38.  
  39. void readAthlete (Athlete *athletes, int n)
  40. {
  41. int i;
  42. for (i=0;i<n;i++){
  43. printf("Please enter the athlete's name. \n");
  44. gets(athletes[i].name);
  45. printf("Please enter the athlete's points. \n");
  46. scanf("%d", &athletes[i].points);
  47. printf("Please enter the athlete's playtime in minutes. \n");
  48. scanf("%f", &athletes[i].playtime);
  49. getchar();
  50.  
  51. }
  52. }
  53.  
  54.  
  55. float computeMAX (Athlete *athletes, int n) {
  56.  
  57. float MAX=0.0, cur;
  58. int i;
  59. for (i=0; i<n; i++) {
  60. cur = athletes[i].points/athletes[i].playtime;
  61.  
  62.  
  63.  
  64. if (MAX<cur){
  65. MAX = cur;
  66.  
  67. }
  68.  
  69. }
  70. return MAX;
  71. }
  72.  
  73. void printAthlete(Athlete *athletes, float MAX, int n) {
  74. int i;
  75. float cur;
  76. for(i=0; i<n; i++) {
  77. cur = athletes[i].points/athletes[i].playtime;
  78. if (cur>=MAX)
  79. printf("%s", athletes[i].name);}
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement