Array and Strings – Algebra – Problem #10

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

Difficulty: hard

Problem Statement

Write a program to input n integers from the keyboard and store them within an array. Declare another array of size n and copy the contents of the first array into the second array as per the following rules: (a) For the elements in the even positions of the first array, into the even positions of the second array in the reverse order. Example: the element in the 1st even position of the 1st array should be placed in the last even position of the 2nd array. Similarly the element in the last even position of the 1st array should be placed in the 1st even position of the 2nd array. For more details see the example given below. (b) For all elements in odd positions of the first array, copy the values in the corresponding odd positions of the second array after multiplying that value with the rounded off value of the square root of the sum of squares of all elements to the right of that element in the first array. Round off the square root value to a perfect integer (lower integer in case of decimal part being less than 0.5 and next higher integer in case the decimal part is greater than or equal to 0.5). In case no numbers exist to the right hand side for an odd position number, copy the number as it is in the corresponding odd position of the second array. You can input the original array as you wish. Read the question very carefully along with the example shown and understand the logic. For output display the second array only. Example: (Please take the input and display the output as shown) Input: 2 6 7 4 9 3 Output: 28 3 70 4 27 6 [Reason: The even position numbers are copied in reverse order in even positions only. For the odd position numbers, say the number at position 1 i.e ‘2’ of the input array, sum of squares of all elements to the right of ‘2’ in the original array = 191. Square root of 191 is 13.82, so the rounded value is 14, now multiply the original number ‘2’ with 14 to get 28, which is stored in the 1st position of the second array. Apply the same rule for all odd position elements. In case there are no elements to the right of the input array, then copy the value as it is in the second array.]

Back to Lab Problems
Array and Strings/Algebra/Problem #10

Lab Problem Statement

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

Interactive C Compiler · Problem #10

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.