0 votes
202 views
in C programming by (98.9k points)
edited
Write a program to store the name, runs, scored and wickets taken of n cricketer using structure display the output in tabular form .

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include<stdio.h>
struct cricketer
{
    int runs,wickets;
    char name[25];
}player[100],t;

void main()
{
    int i,j,n;
    printf("Enter the no of cricket players\n");
    scanf("%d",&n);
    printf("Enter player info as name , wickets taken , runs scored\n");
    for(i=0;i<n;i++)
    {
        scanf("%s %d %d",player[i].name,&player[i].wickets,&player[i].runs);
    }
    
        
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(player[j].runs>player[j+1].runs)
            {
                t=player[j];
                player[j]=player[j+1];
                player[j+1]=t;
            }
        }
    }
    
    printf("\nCricketer info in terms of runs scored from lowest to highest\n");
    printf("\nNAME\t\tWICKETS\t\t\tRUNS_SCORED\n");
    printf("-------------------------------------------------------------------------------\n");

    for(i=0;i<n;i++)
    {
        printf("%s\t\t\t%d\t\t\t%d\n",player[i].name,player[i].wickets,player[i].runs);
    }
}

 

Related questions

0 votes
1 answer 124 views
0 votes
1 answer 208 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...