Functions and Recursions – Arithmetic – Problem #3

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

Problem Statement

2. Write a C program that would allow performing various types of operations on an integer array. It should have the following functions main: Inside the main function declare an integer array of size 40. the main function should then perform the following in a loop: a) display the following menu choice, b) read the user choice and c) call the appropriate function based on the user choice. It should exit when the user enters either 0 or any number greater than 8. When the user gives option 1 (fill function), the size of the array (0<size <=40)should be obtained from the user. You can make either the size as a global variable or pass it as a parameter to other functions. i. Fill: Enter 1 ii. Exchange: Enter 2 iii. Rotate right: Enter 3 iv. Rotate left: Enter 4 v. Sort: Enter 5 vi. Search: Enter 6 vii. Analyze: Enter 7 viii. Exit: Enter 0, 8 or higher number fill: This function should take an integer array and its size as two parameters. It should fill the array with random integral numbers in the range [100,999] generated by calling the (rand) library then display the array contents nicely formatted. [5 Marks] exchange: This function should take an integer array and its size as its parameters. It should first display the elements of the original array received as its input. It should then exchange the lower and upper halves of the array (first half elements of the array should be the last half and vice versa) and display the resultant array. If the number of elements in the array is odd, the middle element remains undisturbed. Do not use an extra array for implementing the exchange operation. [5 Marks] rotate right: This function should take an integer array and its size as its parameters. It s display the elements of the original array received as its input. It should then right rotate one position (the last element should become the first element) and then display the result [5 Marks] rotate left: This function should take an integer array and its size as its parameters. It s display the elements of the original array received as its input. It should then left rotate one position (the first element should become the last element) and then display the result [5 Marks] sort: This function should take an integer array and its size as its parameters. It should display the elements of the original array received as its input. It should then sort the array( using any algorithm that you are familiar with), and display the sorted array. [5 Marks] search: This function should take an integer array and its size as its parameters. It should display the elements of the original array received as its input. It should then ask the user the integer value to be searched. It should then perform a linear search for the element an the array index at which the element is located. If the element is not present in the array display "Not found." [5 Marks] analyze: This function should take an integer array and its size as its parameters. It should display the elements of the original array received as its input. It should then display all increasing sequence of consecutive numbers and also display the largest increasing sequence. It may happen that there are no increasing sequences of numbers. In this case, it should then output an appropriate message. If there are multiple largest sequence, pointing out any one of them would be fine. Example: if the array elements are 1,5,3,2,7,15,23,12,15,21, then it should display: The increasing sequences are: (1,5,3), (2,7,15,23), (12,15,21) and the largest increasing sequence is (2,7,15,23). (10 Marks]

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #3

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #3

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.