Question: Define a structure called “Cricket” that will describe the following information: player name, team name and batting average. Using the structure, declare an array player with 50 elements and write a program to read the information about all the 50 players and print a team-wise list containing names of players with their batting average.
For video explanation, stay tuned…. it will come soon.
Source Code:
#include <bits/stdc++.h>
struct Cricket{
char playername[100];
char teamname[25];
float average;
}player[51];
int main()
{
int i,j,n,p;
char tempteam[25],tempplayer[100];
float tempaverage;
printf(“How many informations of players you want to give as input? “);
scanf(“%d”,&n);
printf(“Enter %d\nPlayer Name\nTeam Name\nBatting Average\nin three different lines.\n\n”,n);
for(i=1;i<=n;i++)
{
scanf(“\n”,&p);
gets(player[i].playername);
gets(player[i].teamname);
scanf(“%f”,&player[i].average);
}
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-i;j++)
{
if(strcmp(player[j].teamname,player[j+1].teamname)>0)
{
strcpy(tempteam,player[j].teamname);
strcpy(player[j].teamname,player[j+1].teamname);
strcpy(player[j+1].teamname,tempteam);
strcpy(tempplayer,player[j].playername);
strcpy(player[j].playername,player[j+1].playername);
strcpy(player[j+1].playername,tempplayer);
tempaverage=player[j].average;
player[j].average=player[j+1].average;
player[j+1].average=tempaverage;
}
}
}
strcpy(tempteam,player[1].teamname);
printf(“Team Name: %s\n”,tempteam);
printf(“\tPlayer Name\tBatting average\n”);
for(i=1;i<=n;i++)
{
if(strcmp(tempteam,player[i].teamname)!=0)
{
strcpy(tempteam,player[i].teamname);
printf(“Team Name: %s\n”,tempteam);
printf(“\tPlayer Name\tBatting average\n”);
}
printf(“\t%10s\t%15.2f\n”,player[i].playername,player[i].average);
}
return 0;
}
Of course, what a splendid site and enlightening posts, I surely will bookmark your site.Best Regards!
I’ve read several excellent stuff here. Definitely price bookmarking for revisiting. I surprise how a lot effort you set to create this kind of great informative website.
Keep functioning ,fantastic job!
Howdy, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me crazy so any help is very much appreciated.
You completed certain nice points there. I did a search on the issue and found nearly all folks will agree with your blog.