A record contains name of a footballer, his age, number of games he has played and
the average number of goals has scored in each match. Create an array of structure to
hold records of 20 such players and then write a program to read these records.
Program would able to tell the name of player that has played maximum number of
matches, the name of youngest player and a player name who scored is lowest.
#include <stdio.h>
struct footballer{
char name[20];
int age;
int no_games;
int avg_goals;
};
int main()
{
//Create an array of structure to
//hold records of 20 such players and then write a program to read these records.
struct footballer fb[20];
printf("Enter Records of 20 footballers:\n");
int i;
int ageArr[20];int gamesArr[20];int goalsArr[20];
for(i=0;i<20;i++){
printf("\nEnter Name:");
scanf("%s",fb[i].name);
printf("\nEnter age:");
scanf("%d",&fb[i].age);
ageArr[i]=fb[i].age;
printf("\nEnter number of games:");
scanf("%d",&fb[i].no_games);
gamesArr[i]=fb[i].no_games;
printf("\nEnter average goals:");
scanf("%d",&fb[i].avg_goals);
goalsArr[i]=fb[i].avg_goals;
}
int minAge=ageArr[0];
int maxGame=gamesArr[0];
int minGoal=goalsArr[0];
for(i=0;i<20;i++){
if (ageArr[i]<minAge){
minAge=ageArr[i];
}
if (gamesArr[i]>maxGame){
maxGame=gamesArr[i];
}
if (goalsArr[i]<minGoal){
maxGame=goalsArr[i];
}
}
for(i=0;i<20;i++){
if (minAge==ageArr[i]){
printf("The youngest player is: %s",fb[i].name);
}
if (maxGame==gamesArr[i]){
printf("The player with maximum games is: %s",fb[i].name);
}
if (minGoal==goalsArr[i]){
printf("The player with minimum goals is: %s",fb[i].name);
}
}
return 0;
}
Comments
Leave a comment