Question: You will implement a simple function, generate_random (int arr[], int cnt). The function generates non-duplicated random numbers and stores them to the array address (arr).

 You will implement a simple function, generate_random (int arr[], int cnt).The function generates non-duplicated random numbers and stores them to the array

You will implement a simple function, generate_random (int arr[], int cnt). The function generates non-duplicated random numbers and stores them to the array address (arr). The second argument (cnt) indicates how many numbers need to be generated. You can assume that the generated random numbers are between 1 ~ 9 and cnt is the size of array (less than 10). For function call, generate_random (arr, 6) arr[] = {5, 2, 1, 4, 6, 3} valid valid arr[] = {1, 3, 4, 2, 5, 7} arr[] = {9, 5, 2, 3, 1,5) invalid ('5' is duplicated) arr[] = {9, 5, 2, 3, 1} invalid (generated numbers is 7) invalid (generated numbers is 5) arr[] = {9, 5, 2, 3, 1, 4, 6} The main function will call generate_random () to generate non-duplicated numbers. arr: .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 (up to 9 numbers) If you call generate_random (arr, 9), the array (arr ) will include all numbers from 1 to 9. You will also need to change the second parameter (cnt) to test your code

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!