Sunday, 30 August 2015

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 wire a program to read the information about all the 50 players and print a list

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 wire a program to read the information about all the 50 players and print a list
1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  #include<string.h>  
4:  struct cricket  
5:  {  
6:        char nm[20],team[20];  
7:        int avg;  
8:  };  
9:  #define total 5  
10:  int main()  
11:  {  
12:        struct cricket player[total],temp;  
13:        int i,j;  
14:        clrscr();  
15:        for(i=0;i<total;i++)  
16:        {  
17:              printf("For player %d\n",i+1);  
18:              printf("Enter the name of player : ");  
19:              fflush(stdin);  
20:              gets(player[i].nm);  
21:              printf("Enter the team : ");  
22:              fflush(stdin);  
23:              gets(player[i].team);  
24:              printf("Enter the batting average : ");  
25:              fflush(stdin);  
26:              scanf("%d",&player[i].avg);  
27:        }  
28:        printf("\nTeam    Name    Average\n");  
29:        printf("               \n");  
30:        for(i=0;i<total;i++)  
31:        {  
32:              printf("%-10s %-10s %7d\n",player[i].team,player[i].nm,player[i].avg);  
33:        }  
34:        getch();  
35:        return 0;  
36:  }  

No comments:

Post a Comment