Question: C language program Write a program to do the following tasks. Generate x random integers, the values of which are in the range [2, y].

C language program

Write a program to do the following tasks.

Generate x random integers, the values of which are in the range [2, y]. The values of x and y are decided by the user, and both no larger than 100.

Calculate and print the number of times each integer in [2, y] occurred in these x random integers. For example, suppose x=9, y=6 and the generated random integers are

4, 4, 3, 6, 4, 4, 3, 2, 6

then the result is

2: 1

3: 2

4: 4

5: 0

6: 2

where 2: 1 means 2 occurs once, 3: 2 means 3 occurs twice and so on.

Print the values in [2, y] in decreasing order of the number of times they occurred. If two values in [2, y] occurred the same number of times, they should be decreasingly ordered by their own values. With the above example, the result is

4, 6, 3, 2, 5

where 6 is ordered before 3 since 6 is larger than 3, although they both occurred twice.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!