Functions and Recursions – Geometry – Problem #5
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Read a positive integer n (n <= 20) and print it. Read the elements of an n by n 2-D matrix in which every element is distinct. Print the array elements neatly row-wise. Then read in a positive integer k and find the k-th largest element in the matrix (without moving the matrix elements from their locations) and print the k-th largest element along with its location index [i,j]. Next, you will sort all the elements of each row separately in ascending order and print the array column-wise (that is first printed line is column 1, 2 nd printed line is column 2 and so on) after all rows are sorted. Now you will find the new location of the k-th largest element [p,q] and print it. [It is recommended that you write your own functions for k-th largest and sorting, most preferably recursive functions. If you do not use your own functions you will get at most 10 marks if your code is correct. If you use correct non- recursive functions for finding k-th largest and sorting, you will get 3 additional marks for each and so a possible maximum of 16. If you write correct recursive functions for finding k-th largest and sorting, you will get 5 additional marks each and so a possible maximum of 20.] Save the file as A12_<Roll Number>.c (example A12_21AG10002.c). Build, Run and Test it for the given data as well as your own data. Then upload the .c file for the Assignment. [20 Marks: 5 marks for intermediate submission, 15 marks for final submission] In particular, you will do the following: 1. Read in a positive integer n and print it suitably. Create a new line. 2. Read in an n by n matrix into a 2-D array and print it row-wise. Create a new line. 3. Read in an integer k and find the k-th largest element of the matrix using a function largek(….) with appropriate arguments, and print it along with its location index. If k is more than the number of elements of the matrix or less than 1, print a suitable message. 4. Sort each row of the array separately using a function sortr(…) with appropriate arguments, in ascending order and print this version in a column-wise manner. 5. Find the new location of the k-th largest element in the updated array and print the location index. [Do not call any Library Functions other than scanf, printf. You may use your own user defined functions] Test Data: Test it with your own data