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
TLE 10 - ICT
Kipish [7]

Answer:

Information And Communication Technology

5 0
2 years ago
Mr. Lee wants to show his class a presentation. Which device will display an enlarged view of his presentation?
Gnesinka [82]
A projector would make his presentation bigger.<span />
3 0
3 years ago
Which domain will redirect you to the amazon website?
Vinvika [58]

Answer:

Amazon.com

Explanation:

Every online business has a domain name that redirects to thier website usually has this format https:// of http:// followed by the domain name.

3 0
3 years ago
Write pseudocode to solve the following problem: You are given an array A[1 . . . n] whose each element is a point of the plane
bixtya [17]

Answer:

Answer explained below

Explanation:

void bubbleSort(int X[], int Y[], int n)

{

   int i, j;

   for (i = 0; i < n-1; i++)      

     

   // Last i elements are already in place

   for (j = 0; j < n-i-1; j++)

       if (X[j] > X[j+1])

{

swap(X[j],X[j+1])

swap(Y[j],Y[j+1]);

}

       if (X[j] == X[j+1]&&Y[j]<Y[j+1])

{

swap(X[j],X[j+1])

swap(Y[j],Y[j+1]);

}

}

Since the above algorithm contains 2 nested loops over n.

So, it is O(n^2)

5 0
3 years ago
Five corporations own over 90 percent of the media in the US.<br> 1.True<br> 2.False
avanturin [10]
<span>Five corporations own over 90 percent of the media in the US : </span>1.True.

7 0
3 years ago
Other questions:
  • Array elements must be ________ before a binary search can be performed.
    8·1 answer
  • Applying what formatting option to your excel workbook will make it easier to read when printed out?
    13·1 answer
  • A(n) _____ is a type of man-in-the-middle attack where an attacker captures the data that is being transmitted, records it, and
    15·2 answers
  • Eugene wants to indent a paragraph, but the ruler is not present. Which tabs could Eugene use in order to accomplish his goal?
    6·2 answers
  • Which two technologies support the building of single-page applications? and are two technologies helpful in building single pag
    12·1 answer
  • Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
    13·1 answer
  • What are registers in ICT used for?
    5·1 answer
  • Decision support systems help managers use structured data to identify problems and find solutions to business-related problems.
    10·1 answer
  • What should you do when you are working on an unclassified system and receive an email.
    10·1 answer
  • Which type of network allows backups and network security to be centrally located?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!