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
Which characteristics support an agile mis infrastructure?
Paraphin [41]

Answer:

The agile MIS infrastructure includes accessibility, availability, flexibility, performance, portability, reliability, scalability and usability. :)

6 0
3 years ago
Vghfthcnbvhghvngjgjvjgkb, kcnjc cnnfjdhd mc Dan Jfhjc cm. Cm n n hdjfjocnkcnd
seropon [69]

Is this supposed to be a question?

6 0
4 years ago
Read 2 more answers
Do you think that people have a “right” to remain anonymous online? Why or why not?
lara31 [8.8K]

Answer:

Yes

Explanation:

because everyones privacy should be respected

6 0
3 years ago
Clickable text or image that takes you to a different site
hichkok12 [17]
A clickable text or image that takes you to a different site is called a Hyperlink or simply a Link.
3 0
3 years ago
This type of connection is best to use when downloading large files on a network.
Elina [12.6K]
Ethernet is best to use when you have to download large files on a network.
8 0
4 years ago
Other questions:
  • HEY DO U LIKE TRAINS!
    7·1 answer
  • Which organizational pattern would probably be most effective for arranging the main points of a speech with the specific purpos
    15·1 answer
  • (1) In Tamara's science class, the students are learning Which sentence shows an action that is extrinsically
    7·1 answer
  • Select the correct answer. What has enabled engineers to design slim and sleek television sets? A. using Nipkow disks B. increas
    7·1 answer
  • While doing online research you enter this keyword search with a truncation character: man* Which of the following would not be
    15·1 answer
  • Why would you use quotation marks in a search string when conducting an internet search?
    12·1 answer
  • The _________ in Java is passed by value but ______ is passedby reference.
    5·1 answer
  • Which command allows d1 to configure an ip address on one of its physical interfaces?
    9·1 answer
  • Class C Airspace inner ring begins at the __________ and extends vertically (by definition) to MSL charted values that generally
    5·1 answer
  • Zybook C++ 3.21 answer
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!