Question
3 Problems Note: 1) Initialize arrays in all three tasks by random values. 2) The size of the arrays should be input by user. 3)
3 Problems
Note:
1) Initialize arrays in all three tasks by random values.
2) The size of the arrays should be input by user.
3) Write a function void print_array(int a[], int size) for printing.
4)Ask user which task to execute and your code should keep running
until user say so.
Problem 1. Block swap algorithm for array rotation
Write a function rotate(arr[], d, n) that rotates arr[] of size n by d elements.
1 2 3 4 5 6 7
Example: Rotation of the above array by 2 will make array.
3 4 5 6 7 1 2
In your main function:
1) Declare an array of size that input by user.
2) Initialize this array with random values.
3) Display this array
4) Ask user for number of elements to rotate d.
5) Call the user defined function named rotate
6) Display the array again.
Problem 2. k largest elements in an array
Write C++ code for printing k largest elements in an array (size >= 10). Display the array
after initialization and display k largest values in that array.
1) For example, if given array is [1, 23, 12, 9, 30, 2, 50] and you are asked for the
largest 3 elements i.e., k = 3 then your program should print 50, 30 and 23.
2) Take input from a user for value k.
Problem 3. Sorting
1) Initialize an array with random values.
2) Write a function sorting (int arr[]) to sort your array in decreasing order.
3) Display the array before and after calling sorting function in main function.
Thanks in advance for the help.
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