Array and Strings – Arithmetic – Problem #6
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Part-I Submit one (single) C program. Write a C program to perform the following tasks. 1. Ask for input positive integers n and m. 2. Construct 2 arrays A and B of type int. A should store n positive integers taken in as input, while B should store m positive integers taken in as input. Note that the numbers taken into A, or into B need not be distinct - two numbers in A can be the same. 3. Construct an array C that only stores the distinct numbers of A and B. In an array D, in the corresponding indices store the frequency of these distinct numbers across A and B. Eg. if C[0] = 1, and 1 appears 2 times in A and 2 times in B, then D[0] = 4. 4. Without using another array, you have to do the following: a) If there are n1 distinct even numbers and n2 distinct odd numbers, then the even numbers should be sorted in ascending order and stored in the cells C[0] - C[n1 - 1] b) In array C the odd numbers should be sorted in descending order and stored in the cells starting from cell C[n1]. c) The frequencies in D should be rearranged such that the indices correspond to the final indices of the number in array C. Continuing from the example in part 3, if finally after the required sorting C[4] = 1, then finally it should be that D[4] = 4. 5. Print the numbers of C and their corresponding frequencies as shown in the sample output. Sample Output Enter positive integer n: 5 Enter positive integer m: 6 Enter 5 positive integers for array A: 2 2 1 3 4 Enter 6 positive integers for array B: 1 2 26 14 6 6 The required sorting of the distinct numbers of A and B are: 2 (3) 4 (1) 6 (2) 14 (1) 26 (1) 3 (1) 1 (2)