PPS Practical 52

PPS Practical 52
  • Aim: 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 C program to read the information about all the 50 players and print team wise list containing names of players with their batting average.
  • Code:
    //For turbo C++ remove below comments
    #include <stdio.h>
    //#include<conio.h>
    #include<string.h>
    struct cricket
    {
        char player_name[100];
        char team_name[100];
        float batting_average;
    }player[50],t;
    void main()
    {
        // clrscr();
        int i,j,n=50;
        for ( i = 0; i < n; i++){
            printf("For Player %d\n",i+1);
            printf("Enter player name : ");
            scanf("%s",&player[i].player_name);
            printf("Enter Team name : ");
            scanf("%s",&player[i].team_name);
            printf("Enter Batting Average : ");
            scanf("%f",&player[i].batting_average);
        }
        for ( i = 1; i < n-1; i++){
            for ( j = i; j < n; j++)
            {
                if (strcmp(player[i].team_name,player[j].team_name)!=0){
                    t=player[i];
                    player[i]=player[j];
                    player[j]=t;
                }
            }
        }
        j=0;
        for (i = 0; i < n; i++)
        {
            if (strcmp(player[i].team_name,player[j].team_name)!=0||i==0){
                    printf("\nTeam Name : %s",player[i].team_name);
                    j=i;
                }
            printf("\nPlayer Name : %s",player[i].player_name);
            printf("\nBatting Average : %f",player[i].batting_average);
        }
        // getch();
    }
    

Comments