Functions and Recursions – Arithmetic – Problem #4

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

Difficulty: hard

Problem Statement

In the main program, declare an integer array of size 16 and name it binNum. Fill it randomly with 1 and 0 values by calling the rand() function repeatedly. Display the array of numbers as a binary number. The program should then wait in an infinite loop showing the following options: 1. Display the number in decimal format 2. Display the number in Hexadecimal format 3. Display the number in Octal format 4. Multiply the original binary number by 2 and display the result 5. Divide the original binary number by 2 and display the result 6. Enter new binary number Exit 7. Enter Your Choice (1-6):- Based on the user choice of number shown above, the following functions will be appropriately called. The result will be displayed inside the function and the program will continue waiting in the infinite loop. The program will exit when the user types 6. The different functions of the program are described in the following a. b2d(): It should take an integer array of 1's and 0's as its argument. It should first print this binary number and then compute and then it should compute and print the decimal equivalent considering the array contents as an unsigned binary number. Also it should display the Octal and Hexadecimal equivalents of the computed decimal number using %o and %x formats. b. b2h(): It should take an integer array of 1's and 0's as its argument. It should first print this binary number and then compute and print its Hexadecimal equivalent considering the array as an unsigned binary number. C. b2o(): It should take an integer array of Is and 0s as its argument. It should first print this binary number. It should then compute and print the octal equivalent of the number considering the array contents as an unsigned binary number. d. multiply2(): It should take an integer array of 1's and 0's as its argument. It should first print this binary number and then print the decimal equivalent of the number by calling b2d(). It should then shift the bits left by one bit, and then print the resultant binary number and also the decimal equivalent of this resultant binary number by calling b2d(). e. divide2(): It should take an integer array of 1's and 0's as its argument. It should first print the binary number and then print the decimal equivalent of the number by calling b2d(). It should then shift the bits right by one bit, and then print the binary number and the decimal equivalent of the number by calling b2d(). f.newNum(): Prompt for entering a 16bit unsigned binary number. If arrays are not passed as argument, or global arrays are declared, 20% marks will be deducted. Total=25 Marks]

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #4

Lab Problem Statement

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

Interactive C Compiler · Problem #4

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.