C Program to Print Player Details using Array of Structure

C Program to Print Player Details using Array of Structure:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
struct player
{
    int pno,noi,truns;
    char pname[15];
    float avg;
}s[3];
main()
{
   int i,max=0,j=0;
   void line(void);
   for(i=0;i<3;i++)
   {
       line();
       printf("Enter player %d details...\n",i+1);
       line();
       printf("Enter player number\n");
       scanf("%d",&s[i].pno);
       printf("Enter player name\n");
       scanf("%s",s[i].pname);
       printf("Enter number of innings\n");
       scanf("%d",&s[i].noi);
       printf("Enter total runs\n");
       scanf("%d",&s[i].truns);
       printf("Enter the average\n");
       scanf("%f",&s[i].avg);
   }
   line();
   printf("Players Details...\n\n");
   line();
   printf("PlayerNo\tPlayerName\tNo_Of_inng\tTotalRuns\tAverage\n");
   line();
   for(i=0;i<3;i++)
   {
       printf("%d\t%s\t%d\t%d\t%f\n",s[i].pno,s[i].pname,s[i].noi,s[i].truns,s[i].avg);
   }
   line();
   printf("Player Name having highest average\n");
   line();
   max=s[0].avg;
   for(i=1;i<3;i++)
   {
       if(s[i].avg>max)
       {
           max=s[i].avg;
           j=i;
       }
   }
   printf("PlayerName\tAverage\n");
   line();
   printf("%s\t%f\n",s[j].pname,s[j].avg);
}
void line()
{
    int i;
    for(i=0;i<100;i++)
    {
        printf("_");
    }
    printf("\n");
}

OUTPUT:

__________________________________________________________________________________________________
Enter player 1 details...
____________________________________________________________________________________________________
Enter player number
1
Enter player name
John
Enter number of innings
45
Enter total runs
4500
Enter the average
78
____________________________________________________________________________________________________
Enter player 2 details...
____________________________________________________________________________________________________
Enter player number
2
Enter player name
Smith
Enter number of innings
100
Enter total runs
7500
Enter the average
89
____________________________________________________________________________________________________
Enter player 3 details...
____________________________________________________________________________________________________
Enter player number
3
Enter player name
Virat
Enter number of innings
150
Enter total runs
8000
Enter the average
150
____________________________________________________________________________________________________
Players Details...

____________________________________________________________________________________________________
PlayerNo        PlayerName      No_Of_inng      TotalRuns       Average
____________________________________________________________________________________________________
1       John    45      4500    78.000000
2       Smith   100     7500    89.000000
3       Virat   150     8000    150.000000
____________________________________________________________________________________________________
Player Name having highest average
____________________________________________________________________________________________________
PlayerName      Average
____________________________________________________________________________________________________
Virat   150.000000

Leave a Reply

Your email address will not be published. Required fields are marked *

three × five =