Array and Strings – Geometry – Problem #1

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

Difficulty: hard

Problem Statement

4A. Write a C program which does the following: 1. Declare an array A of integers of size 100. 2. Read an integer n (n ≤ 100) 3. Populate the array A with n random integer numbers between -100 and 100 4. You need to find the position x to split the array so that the sum of elements on both sides A[0..x] and A[x + 1..n-1] are as close as possible. Print the value of i and the sums of both the subarrays 5. Print one of the closet pair of elements in the array. The distance between a pair of elements A[i] and A[j] is the absolute value of A[i] - A[j]. Ex1 : If A=[5, 1, 12, 7, 9, 11, 34, 22, 15], the following will be the output : Array split position is 5 The sums of the left and right subarrays are 45 and 81 One closest pair is 5 and 7 Ex2 : If A=[-5, 1, 12, -7, 9, 11, -24, 22, -15], the following will be the output : Array split position is 3 The sums of the left and right subarrays are 1 and 1 One closest pair is 9 and 11 4B. Given two strings S and Q, you need to check if Q can be formed from the letters in the string S. Write a C program which does the following : 1. Read a string S as given by the user on a single line (length of the string must be less than 100). 2. In a loop, do the following : a) Read a query string Q comprising of the characters a..z only b) If Q is "end", quit the program, otherwise print whether Q can be formed from S. Example : Suppose S is "the lanes and bylanes of Kolkata" Q="baall" - Q can be formed from S. Q="balloon" - Q cannot be formed from S. Q="bybykk" - Q cannot be formed from S. Q="bookin" - Q cannot be formed from S.

Back to Lab Problems
Array and Strings/Geometry/Problem #1

Lab Problem Statement

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

Interactive C Compiler · Problem #1

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.