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
Select the correct answer.
DochEvi [55]

Answer:

ask customers to use strong passwords to protect their accounts

6 0
3 years ago
Read 2 more answers
When entering a formula or function into a cell, most spreadsheet programs require that you begin with some type of symbol, usua
olga_2 [115]
This is a false statement, if that's the question.
4 0
3 years ago
Which prosscess is a form of mechanicel weathering
Alecsey [184]

Answer:

The most common form of mechanical weathering is the freeze-thaw cycle. Water seeps into holes and cracks in rocks. The water freezes and expands, making the holes larger. Then more water seeps in and freezes

4 0
1 year ago
Read 2 more answers
Determine whether the relation represents a function. If it is a​ function, state the domain and range.
slava [35]

Answer:

Yes, the relation is a function

Domain = {-3,1,3,7}

Range = {7,3,1-1}

Explanation:

Given

{(-3,7),(1,3),(3,1),(7,-1)}

To determine if the relation is a function or not, we check if every output has only one corresponding input.

The output are (7,3,1-1) while the input are (-3,1,3,7)

-3 ----;> 7

1 -------> 3

3 -------> 1

7 -------> -1

It is a function since every output only has one corresponding input

To find the domain, we look at the set of input values

Domain = {-3,1,3,7}

To find the range, we look at the set of output values

Range = {7,3,1-1}

3 0
3 years ago
Does anyone else realize how the only tutor is for math never any other subjects?​
Slav-nsk [51]

Answer:

yes I do and I wonder why ??

7 0
3 years ago
Other questions:
  • Describe in 2–3 sentences how you would use the autosum shortcut.
    9·2 answers
  • Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[
    13·1 answer
  • How would a programming language that allows programs to run on any operating system be classified?
    11·1 answer
  • How can i learn about networks
    15·1 answer
  • Mobile computing has two major characteristics that differentiate it from other forms of computing. What are these two character
    8·1 answer
  • The _________ in Java is passed by value but ______ is passedby reference.
    5·1 answer
  • Why is a high-quality bond typically considered a lower-risk investment than a stock
    10·2 answers
  • Write a programmer defined function that compares the ASCII sum of two strings. To compute the ASCII sum, you need to compute th
    6·1 answer
  • The BaseballPlayer class stores the number of hits and the number of at-bats a player has. You will complete this class by writi
    6·1 answer
  • Choose the answer that best completes the
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!