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
True [87]
3 years ago
11

Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single

parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value. The function name: decimalToBinaryRecursive The function parameter: An integer to be converted to binary Your function should return the binary representation of the given value as a string Your function should not print anything Your function should use recursion. Loops are not allowed.

Computers and Technology
1 answer:
Delicious77 [7]3 years ago
5 0

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <string>

using namespace std;

string decimalToBinaryRecursive(int n) {

   if(n == 0) {

       return "0";

   } else if(n == 1) {

       return "1";

   } else {

       int d = n % 2;

       string s;

       if (d == 0) {

           s = "0";

       } else {

           s = "1";

       }

       return decimalToBinaryRecursive(n/2) + s;

   }

}

int main() {

   cout << decimalToBinaryRecursive(0) << endl;

   cout << decimalToBinaryRecursive(1) << endl;

   cout << decimalToBinaryRecursive(8) << endl;

   return 0;

}

See the output image below

You might be interested in
Create a list words = ['is', 'NLP', 'fun', '?']. Use a series of assignment statements (e.g. words[1] = words[2]) and a temporar
Svetlanka [38]

Answer:

words = ['is', 'NLP', 'fun', '?']

tmp = words[1]

words[1] = words[0]

words[0] = tmp

words[3] = '!'

print(words)

Explanation:

- Create the list

- Assign the new values using <em>tmp</em> variable

- Print the result

Since tuples in Python are unchangeable, you cannot transform the list using tuple assignment.

5 0
3 years ago
A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" paramete
Firdavs [7]

Answer:

The answer is "Option a"

Explanation:

  • In java, the main function is the point of entry of every java program. Its syntax always starts "public static void main" with (String args[]), in which it can also be modified by the name of the string array name.
  • It also known as an entry point is the key process. In any program, it is the first method, that executes whenever you run a program. There is one main feature in a regular app that uses instances of certain classes to operate.
4 0
3 years ago
Biometric devices are often associated with computer and data security. True False
Leya [2.2K]

Answer:

True

Explanation:

5 0
3 years ago
A colleague has included you on an email that is irrelevant to you, but it continues to come to your inbox because people are us
Law Incorporation [45]

on google there is a mute function with the 3 dots on the top and outlook has it in the same location but under the word of "ignore"

7 0
3 years ago
A _______ contains several blades of differing thicknesses and is used to measure the clearance between parts.
motikmotik
A Feeler Gauge. It is a tool used to measure gap widths
3 0
3 years ago
Other questions:
  • Famed science fiction writer H. G. Wells once envisioned something to store vast amounts of information. What did he call it?
    15·2 answers
  • Which of the following is a social news-sharing service?
    10·2 answers
  • What type of software translates a programmer’s statements to binary form?
    10·1 answer
  • SQL a. has become the de facto standard database language b. can be used to define database systems c. both a. and b. d. none of
    10·1 answer
  • The method main of a class is called when you instantiate an object of that class like this: Box myBox = new Box();
    9·1 answer
  • You are planning trip to South America and and are worried about your devices with private keys being stolen. So you decide to s
    9·1 answer
  • "Explain the functionality of the different layers found in the network protocol stack of an operating system such as Linux"
    7·1 answer
  • Which of the following is a characteristic of vector graphics?
    15·2 answers
  • Hello everyone! can anybody help me? i need help with computing.
    10·1 answer
  • Which control segment communicates with the satellites? OA master stations O B. monitoring stations O C. ground antennas D. cont
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!