In this assignment, you write a C++ program that outputs each number and its rank in the list from a given list of 20 distinct integers. The rank of a number x in list L is the number of elements smaller than x in L.

For example,

Input: 20 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1
Output: (20 19) (2 1) (3 2) (4 3) (5 4) (6 5) (7 6) (8 7) (9 8) (10 9) (11 10) (12 11) (13 12) (14 13) (15 14) (16 15) (17 16) (18 17) (19 18) (1 0)
/* the order of the pairs in the list in the output is not important */

Your program must implement the following algorithm:

Read input of N=20 integers into array A

Scan array A as index i runs from 0 to N-1

calculate the rank of A[i] by counting all numbers that are smaller than A[i]

Output all elements and their ranks in list L (i.e. array A)

In this assignment you are asked to implement list L as an array of size N such that each element in L is a structure that contains an element and its rank in array A.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.