QuestionPaper SetORANGE
QuestionPaper SetORANGE
General Instructions
● This paper consists of seven questions (Q1, Q2, Q3, Q4, Q5, Q6 and Q7), each carrying 11 marks.
● The paper is binary marked, so if your answer exactly matches the answer expected in the main.c
file for that specific question, you get 11 marks, else you get 0 marks for that question.
● Read all the instructions and the problem statements very carefully before attempting.
● Carefully follow the submission instructions mentioned below before uploading your solution on
the DomJudge portal.
● If you submit multiple submissions, only the latest one will be considered for evaluation. Whatever
you submit on the DomJudge portal will be considered as final. It is your responsibility to make
sure that you are submitting the correct file. Later, if some student claims that he/she has
mistakenly submitted the wrong file, we won’t be entertaining any such request and we will
evaluate based on whatever is submitted on the DomJudge portal.
● After submitting, on the portal you have an option to verify that you have submitted the correct
files. Ensure you verify it before the countdown timer expires.
If you do any of the above dont’s you will definitely incur a heavy penalty.
Submission Instructions
Your final submission should be a zip folder with the name as your 13-digit ID number, e.g.,
2023A2PS0001P with 18 files in all (namely myScript.sh, main.c, f1.c, f2.c,..., f7.c, f1.h, f2.h,..., f7.h,
f6_helper.c, f7_helper.c).
Page 1 of 6
Problem Statements
Q1. In this question, you need to sort three numbers a, b, c in ascending order. Complete the
function aSort in f1.c. You are supposed to store the smallest number using the pointer n1, the
middle number using the pointer n2, and the greatest number using the pointer n3. The integer
pointer variables, n1, n2, and n3 are being passed by reference from main.c into f1.c.
Sample 1:
Enter numbers a b c: 20 10 30
After sorting
10 20 30
Sample 2:
Enter numbers a b c: 1 8 1
After sorting
118
Sample 3:
Enter numbers a b c: -1 -1 -1
After sorting
-1 -1 -1
Q2. In this question, given n two-dimensional points (i.e., x, y coordinates in the cartesian plane),
you are required to find out the Euclidean distance between the two points which are closest to
each other.
Hint 01: You may use mathematical functions such as pow(), sqrt() if required. These functions are
included in math.h header file.
Hint 02: pow(a,b) — returns a raise to b; sqrt(a) — returns the square root of a
Sample 1:
Sample 2:
Q3. In this question, you are given an array of integers arr and an unsigned integer rotateBy. You
need to rotate the array elements to the right rotateBy number of times.
Complete the function rotateArray in f3.c. You do not need to return or print anything in the
function rotateArray. Just make changes in the array being passed into the function rotateArray
itself.
Sample 1:
Rotated array: 4 5 1 2 3
Sample 2:
Rotated array: 30 40 10 20
Q4. In this question, you are given an array of integers arr. You are required to remove the adjacent
duplicates from the string. In the main function, you are given a code prompting the user to enter a
string as input. After processing, it should output a string without adjacent duplicates. Your code
should satisfy the following samples.
Sample 1:
Sample 2:
Page 3 of 6
Q5. You are given a square matrix mat of size nxn. You have to rotate the matrix by 90 degrees in
CLOCKWISE direction (See samples below).
Complete the function rotateMatrix in f5.c. You do not need to return or print anything in the
function rotateMatrix. Just make changes in the matrix mat itself.
Sample 1:
Rotated Matrix:
741
852
963
Sample 2:
Rotated Matrix:
3951
4062
5173
6284
Q6 & Q7. In the main function, you already have code to prompt the user to enter the coefficients
and exponents for two polynomials, poly1 and poly2. Using a do-while loop, you take input from the
user for coefficients and exponents individually to create a term for polynomials in the linked list
using the addTerm function. Following that, you invoke the function addPolynomial, passing two
heads of the linked list (Polynomials) as an argument and interchangeCoefficients, passing the
address of two polynomials. The addPolynomial function adds the two linked lists (Polynomials) and
returns the head of the result polynomial, you can use addTerm function to create the result
Polynomial and interchangeCoefficients function interchanges the coefficient of polynomials based
on their exponents.
Complete the following functions:
(a) addPolynomials
(b) interchangeCoefficients
Your task is to code the functions addPolynomials and interchangeCoefficients in f6.c and f7.c,
respectively, to satisfy the following samples. (Enter: “0 0” to exit from entering the coefficient and
exponents of a polynomial)
Page 4 of 6
Sample 1:
Enter Polynomial 1 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 9 5
Enter coefficient and exponent: 5 4
Enter coefficient and exponent: 3 1
Enter coefficient and exponent: 1 0
Enter coefficient and exponent: 0 0
Enter Polynomial 2 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 1 4
Enter coefficient and exponent: 2 3
Enter coefficient and exponent: 1 2
Enter coefficient and exponent: 5 1
Enter coefficient and exponent: 6 0
Enter coefficient and exponent: 0 0
Coefficients Interchanged
Sample 2:
Enter Polynomial 1 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 5 2
Enter coefficient and exponent: 1 1
Enter coefficient and exponent: 6 0
Enter coefficient and exponent: 0 0
Enter Polynomial 2 (Enter coefficient and exponent, separate with space. Enter 0 0 to stop):
Enter coefficient and exponent: 3 3
Enter coefficient and exponent: 7 2
Page 5 of 6
Enter coefficient and exponent: 4 1
Enter coefficient and exponent: 3 0
Enter coefficient and exponent: 0 0
Coefficients Interchanged
—----------------------------------------------------------------------------------------------------
Page 6 of 6