Example 91: Cricket Scores

Learn how to print cricketer details sorted in an ascending order based on their scores.

We'll cover the following

Problem

A record contains the name of a cricketer, the age, the number of test matches he has played, and the average runs he scored in each test match. Create an array of structures to hold records of 5 such cricketers, and then write a program to read these records and arrange them in ascending order by average runs. Use the qsort() standard library function.

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Note: To run your solution or our given solution, follow the following steps:

  • Click on the run button.
  • Wait for the 4 steps to complete, and then switch to the terminal tab.
  • In the terminal tab, write the following command:
    gcc main.c -o main
    Follow it with this command:
    ./main

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.