Starting from:

$30

CS2092D-ASSIGNMENT 1 Solved

QUESTIONS

 

1.    Write a program to convert a given octal number (base 8) to its equivalent decimal number (base 10). For example, the decimal number corresponding to the octal number (205)8 is 2∗82+0∗81+5∗80 = (133)10.

Input format:

•   The input is an octal number n ∈ [0 − 104], such that every digit in n ∈ [0 − 7].

Output format:

•   The output is a decimal number equivalent to the given input.

Sample Input: 1534

Sample Output: 860

2.    Write a program that print the count of elements present more than once in an array A of integers and print all the positions where the element is present(array indexing starts from 0).

Input format:

•   The first line of the input contains an integer n ∈ [0,104], the size of the array A.

•   The second line lists the n elements in A, as space-separated integers in the range [−1000,1000]. Output Format:

•   The output contains the repeated element in A, the positions of the element, and its count separated by a space.

•   The output should print the repeated elements in their order of occurrence in the array A, i.e., the first line of output contains first repeated element, its positions, and count followed by the next repeated elements in upcoming lines.

•   If there is no repeated elements in A, print -1.

Sample Input:

6

4 3 12 5 4 3

Sample Output :

4 0 4 2

3  1 5 2

3.    Write a program to toggle the case of each character in a given string.

Input format:

•   The input is a string with uppercase, lowercase characters ∈ [A − Z,a − z] and space.

Output format:

•   The output is a string with all the lower case letters converted to upper case and the upper case letters converted to lower case.

Sample Input : NaTIonAL InsTituTE oF TecHnoLoGY

Sample Output : nAtiONal iNStITUte Of tEChNOlOgy

4.    Write a program to convert a decimal number to its binary. Perform circular left shift and circular right shift on the binary equivalent by k positions, where k is a random integer. Your program must contain the following function.

•   Convert(n) - A function that takes as input a decimal number n and convert it to binary equivalent b.

Input format:

•   The input is two integers n ∈ [0,104] and k ∈ [0,16].

Output format:

•   The first line of the output is 16 bit binary equivalent of the decimal number

•   The second line of the output is 16 bit binary equivalent after left circular shift.

•   The third line of the output is 16 bit binary equivalent after right circular shift.

Sample Input:

128 3

Sample Output:

0000000010000000

0000010000000000

0000000000010000

5.    Write a program to merge two integer arrays A and B. Print the resulting array such that repeated elements appear first, followed by non-repeating elements.

Input format:

•   The first line of the input contains integers m,n ∈ [0,104], the size of the arrays A and B.

•   The second line lists the m elements in A, as space-separated integers in the range [−1000,1000].

•   The third line lists the n elements in B, as space-separated integers in the range [−1000,1000]. Output Format:

•   The output contains the repeated elements in the resulting merged array of A and B in their order of occurrence followed by the non-repeating elements separated by a space.

•   The non-repeating elements in A should appear before non-repeating elements in B.

Sample Input1:

6 7

2 5 7 2 10 23

8 5 10 6 15 5 7

Sample Output1:

2 2 5 5 5 7 7 10 10 23 8 6 15

Sample Input2:

5 4

8 9 6 5 4

3  4 11 21

Sample Output2:

4  4 8 9 6 5 3 11 21

6.    Write a program to find the GCD of the two integers (the largest integer that divides both of the integers) using recursion.

Input format:

•   The input is two integers a,b ∈ [−105,+105]

•   Both input integers should not be zero.

Output format:

•   The output is the integer which is the GCD of two integers.

Sample Input1:

366 60

Sample Output1: 6

Sample Input2: -10 15

Sample Output2:

5

More products