Articles

Define a structure called cricket that will d

July 18, 2011 at 21:31:31
Specs: Windows XP

Define a structure called cricket that will describe the following information
Player name
Team name
Batting average
Using cricket, declare an array player with 10 elements and write a program to read the information
about all the 10 players and print a team wise list containing names of players with their batting
average.

See More: Define a structure called cricket that will d

Report •


#1
July 18, 2011 at 21:32:08

#include<stdio.h>
#include<conio.h>
#include<string.h>
struct cricket
{
char nm[20],team[20];
int avg;
};
#define total 5
int main()
{
struct cricket player[total],temp;
int i,j;
clrscr();
for(i=0;i<total;i++)
{
printf("For player %d\n",i+1);
printf("Enter the name of player : ");
fflush(stdin);
gets(player[i].nm);
printf("Enter the team : ");
fflush(stdin);
gets(player[i].team);
printf("Enter the batting average : ");
fflush(stdin);
scanf("%d",&player[i].avg);
}
printf("\nTeam Name Average\n");
printf(" \n");
for(i=0;i<total;i++)
{
printf("%-10s %-10s %7d\n",player[i].team,player[i].nm,player[i].avg);
}
getch();
return 0;
}
Output:
For player 1
Enter the name of player : radhe
Enter the team : India
Enter the batting average : 100
For player 2
Enter the name of player : Tiwari
Enter the team : Pakistan
Enter the batting average : 5
For player 3
Enter the name of player : Tendulkar
Enter the team : India
Enter the batting average : 45
For player 4
Enter the name of player : Dhoni
Enter the team : India
Enter the batting average : 48
For player 5
Enter the name of player : Yuvi
Enter the team : India
Enter the batting average : 39
Team Name Average
-----------------------------
India radhe 100
Pakistan Tiwari 5
India Tendulkar 45
India Dhoni 48
India Yuvi 39

Report •
Related Solutions


Ask Question