Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a computer system, integers are represented as a sequence of binary bits of 0 or 1. Binary is a base-2 number system instead of

image text in transcribed

In a computer system, integers are represented as a sequence of binary bits of 0 or 1. Binary is a base-2 number system instead of the decimal (base- 10) system we are familiar with. Write a program which calls a recursive function PrintBinary (int num) that prints the binary representation for a given decimal integer. For example, calling PrintBinary(7) would print 111. Your function may assume the integer parameter is non-negativee The following Figure shows an algorithm for the conversion from a decimal number to a binary number. First, write the decimal number as the dividend and "2" as the divisor. Write the integer answer (quotient) under the long division symbol, and write the remainder (0 or 1) to the right of the dividend. Continue downwards, dividing each new quotient by two and writing the remainders to the right of each dividend, until when the quotient is 0. You will get the binary number by reading the sequence of remainders upwards to the top (starting with the bottom remainder) ccrstrterettcerettetrsttterttrtcrrtrecrsErccr 2156Reminder 278 239 219 29 24 0 0 0 0 21 1561 100111002 One hint to this problem is that you need to work backwards. There is a straightforward way to easily identify and print the last binary digit, but you need to print that digit only after you have printed all the other binary digits Your code must meet these requirements: The program must be written in C You must use recursion to implement the conversion, and define the function prototype as "void PrintBinary(int)" Your program must read a base 10 number to be converted from the standard input and must output the binary number to the standard output. Use sensible variable names. Comment and indent your code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago