C program-Structure of cricket

Posted: January 19, 2012 in Lab 1

Define a structure called cricket that will describe the following
information:

player name
team name
batting average

using cricket ,declare an array player with 50 elements and write a program to read the information about all the players and print a team wise list contaning names of players with their batting average.


#include<stdio.h>
struct cricket
{
char name[20];
char team[20];
float avg;
}player[20];
void main()
{
int n,i;
printf("Enter the number of players");
scanf("%d",&n);
for(i=0;i<n;i++)
 {
printf("Enter player name : ");
fflush(stdin);
gets(player[i].name);
printf("Enter team name : ");
gets(player[i].team);
printf("Enter batting average : ");
scanf("%f",&player[i].avg);
}
printf("PLAYER NAME\tTEAM NAME\tBATTING AVERAGE\n");
for(i=0;i<n;i++)
{
printf("%s\t\t%s\t\t%f\n",player[i].name,player[i].team,player[i].avg);
 }

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s