Structures and Pointers – Geometry – Problem #1
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. Define a structure num which has 2 arrays Bin and Oct. The objective of the 2 arrays is to store the binary representation and octal representation, respectively, of a decimal number that lies between -500 and 500. Bin[0] contains the least significant bit of the binary representation. Negative numbers will be represented as 1’s complement in binary representation. Similarly, Oct[0] contains the least significant bit of the octal representation. Negative numbers will be represented as 8’s complement in the octal representation. 2. Define a 2D array A[][] of type num, where the number of rows is at most 20 and the number of columns is at most 20. 3. Take as input two positive integers n,m 6 20. 4. For 0 6 i < n, 0 6 j < m, take as input a decimal integer aij and store in A[i][j] a structure of type num that stores the binary and octal representations of aij. 5. Define a 2D array B[][] of type bool, where the number of rows is at most 20 and the number of columns is at most 20. 6. Set B[i][j] to 1 if in A[i][j] both the conditions are true: (i) the ith element in the binary representation of aij is 0, (If there is no ith element then consider the value to be 0). (ii) the jth element in the octal representation is at most 4 (If there is no jth element in the octal representation then consider the value to be 0). In all other cases, set B[i][j] to 0. 7. Print B as a 2D array. In other word, if there are n rows and m columns that are filled in B, then the output should be printed in n rows and m columns. You can write your own functions wherever necessary, but proper commenting is required to explain the purpose of the function. Part-II Sample Output Enter positive integer n less than equal to 20: 2 Enter positive integer m less than equal to 20: 2 Enter an integer between -500 and 500 for A[0][0]: 3 Enter an integer between -500 and 500 for A[0][1]: 9 Enter an integer between -500 and 500 for A[1][0]: 1 Enter an integer between -500 and 500 for A[1][1]: -5 The matrix B is as follows: 0 0 1 0