1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bagirrra123 [75]
3 years ago
10

Binary is a base-2 number system instead of the decimal (base-10) system we are familiar with. Write a recursive function PrintI

nBinary(int num) that prints the binary representation for a given integer. For example, calling PrintInBinary(5) would print 101. Your function may assume the integer parameter is non-negative. The recursive insight for this problem is to realize you can identify the least significant binary digit by using the modulus operator with value 2. For example, given the integer 35, mod by 2 tells you that the last binary digit must be 1 (i.e. this number is odd), and division by 2 gives you the remaining portion of the integer (17). What 's the right way to handle the remaining portion
Computers and Technology
1 answer:
Paladinen [302]3 years ago
7 0

Answer:

In C++:

int PrintInBinary(int num){

if (num == 0)  

 return 0;  

else

 return (num % 2 + 10 * PrintInBinary(num / 2));

}

Explanation:

This defines the PrintInBinary function

int PrintInBinary(int num){

This returns 0 is num is 0 or num has been reduced to 0

<em> if (num == 0)  </em>

<em>  return 0;  </em>

If otherwise, see below for further explanation

<em> else </em>

<em>  return (num % 2 + 10 * PrintInBinary(num / 2)); </em>

}

----------------------------------------------------------------------------------------

num % 2 + 10 * PrintInBinary(num / 2)

The above can be split into:

num % 2 and + 10 * PrintInBinary(num / 2)

Assume num is 35.

num % 2 = 1

10 * PrintInBinary(num / 2) => 10 * PrintInBinary(17)

17 will be passed to the function (recursively).

This process will continue until num is 0

You might be interested in
Why doesnt brainly let me skip by watching video?
oksian1 [2.3K]

What do you want to skip in brainly? There isn't anything to skip that I can think of.

4 0
3 years ago
To gain one pound of fat, how many extra calories would you need to consume?
mamaluj [8]
You'll need $3,500 extra calories to gain one pound of fat.

6 0
3 years ago
What is a curson?
sp2606 [1]

Answer:

C. Blinking vertical line on your screen

Explanation:

A cursor is tha blinking vertical line on your screen.

5 0
4 years ago
Buying a house is most likely a long-term goal for a person of which of these
vekshin1

Answer:

B  i think

Explanation:

5 0
3 years ago
Disadvantage do you think one can have if he or she does use electronic media
Dima020 [189]
- discontinuity
- dependence on the electric power
and more
6 0
3 years ago
Other questions:
  • Di bawah ini tampilan submenu pada tab menu insert pada microsoft word 2010,yaitu...
    6·1 answer
  • The advantage of an electronic ____ is that the content can be easily edited and updated to reflect changing financial condition
    10·1 answer
  • Nathan wants to create multiple worksheet containing common formatting styles for his team members. Which file extension helps h
    9·1 answer
  • What is the difference between private inheritance and composition?
    11·1 answer
  • Explain how the use of Git and a shared public Git repository simplifies the process of managing opensource development when man
    8·1 answer
  • All of these valid ways to earn money in microworkers except
    8·1 answer
  • Which components must all tasks have? Check all that apply.
    10·1 answer
  • Make The PYTHON Code<br><br> print first 3 character of a string - given "Seattle" expected "Sea"
    14·1 answer
  • Windows is a GUI Operating System, what is the other type?
    8·1 answer
  • When patel’s advertising co. decided to upgrade its computer network, many people were involved in the decision. In b2b buying s
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!