Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_SIZE 50
- typedef struct athletesID{
- char name[MAX_SIZE+1];
- int points;
- float playtime;
- } Athlete;
- void readAthlete (Athlete *athletes, int n);
- float computeMAX (Athlete *athletes, int n);
- void printAthlete(Athlete *athletes, float MAX, int n);
- int main()
- {
- int numA;
- float MAX;
- Athlete *athletes;
- printf("Enter the number of athletes. \n");
- scanf("%d", &numA);
- getchar();
- athletes = (Athlete*)malloc(sizeof(Athlete)*numA);
- readAthlete (athletes, numA);
- computeMAX (athletes, numA);
- printAthlete(athletes, MAX, numA);
- free(athletes);
- return 0;
- }
- void readAthlete (Athlete *athletes, int n)
- {
- int i;
- for (i=0;i<n;i++){
- printf("Please enter the athlete's name. \n");
- gets(athletes[i].name);
- printf("Please enter the athlete's points. \n");
- scanf("%d", &athletes[i].points);
- printf("Please enter the athlete's playtime in minutes. \n");
- scanf("%f", &athletes[i].playtime);
- getchar();
- }
- }
- float computeMAX (Athlete *athletes, int n) {
- float MAX=0.0, cur;
- int i;
- for (i=0; i<n; i++) {
- cur = athletes[i].points/athletes[i].playtime;
- if (MAX<cur){
- MAX = cur;
- }
- }
- return MAX;
- }
- void printAthlete(Athlete *athletes, float MAX, int n) {
- int i;
- float cur;
- for(i=0; i<n; i++) {
- cur = athletes[i].points/athletes[i].playtime;
- if (cur>=MAX)
- printf("%s", athletes[i].name);}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement