Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question B. (15 marks] Write a program to do the following tasks. Generate x random integers, the values of which are in the range [2,
Question B. (15 marks] 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 w! 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 occuired twice
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started