Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS151 / KCS251 Programming for Problem Solving - Using C Language


Lab Exercises


36. Define a structure called cricket with player name, team name, batting average, for 55 players & 5 teams. Print team-wise list contains names of players with their batting average.


/*
 File: Prgrm36.c
 Author: Aditya Saini
 Date: Jan 20, 2021
 Description: Program to print team-wise list contains names of players with their batting average.
*/

#include <stdio.h>
#include <string.h>

typedef struct cricket
{
     char name[30];
     char team[20];
     float bat_avg;
} cricket;

int main (void)
{
     cricket player[55];
     char team[5][20];
     int i, j;

     //Input teams details
     for (i = 0; i <= 4; i++)
     {
          printf ("Input Team Name: ");
          fflush (stdin);
          gets (team[i]);

          //Input players details
          for (j = i * 11; j <= (i + 1) * 11 - 1; j++)
          {
               printf ("Input %d player details\n", j - (i * 11) + 1);
               printf ("Name: ");
               fflush (stdin);
               gets (player[j].name);
               printf ("Batting Average: ");
               scanf ("%f", &player[j].bat_avg);
               strcpy (player[j].team, team[i]);
               printf ("\n");
          }
          printf ("\n");
     }

     //Print team-vise player details
     printf ("Teams\n\n");
     for (i = 0; i <= 4; i++)
     {
          printf ("Team %d: %s\n", i + 1, team[i]);
          printf ("Sr.\tPlayer Name\t\tBatting Average\n");
          for (j = i * 11; j <= (i + 1) * 11 - 1; j++)
               printf ("%d.\t%s\t\t\t%.2f\n", j - (i * 11) + 1, player[j].name, player[j].bat_avg);
          printf ("\n");
     }

     return 0;
};



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib