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
Which of the following words best describes the word icon ​
Usimov [2.4K]

Answer:

symbol

Explanation:

7 0
2 years ago
Read 2 more answers
What paper should I use for technical drawing?
Vitek1552 [10]

Answer:

classic A4 format, and therefore for 210 x 297 mm sheets

7 0
3 years ago
How often should you typically monitor your checking account? Yearly Daily Every three months Monthly
Maslowich
I’d say monthly. It probably wouldn’t kill you to do it every three months though.
7 0
3 years ago
Read 2 more answers
Rachelle's computer has frequent system crashes and it takes a long time to access files and folders. What hardware component is
9966 [12]
System crashes, viruses and fragmented file systems are hallmarks of Windows systems, but your teacher is probably looking for Hard Drive for the answer.
8 0
3 years ago
Materials such as copper, silver, and aluminum through which electric energy passes freely are called
nasty-shy [4]
These materials are called conductors
6 0
3 years ago
Other questions:
  • If you enter 234.567 into a cell that is formatted to display 1 decimal point place, what is the value stored in the cell
    9·1 answer
  • Typohunting is registering a domain name that is similar to a trademark or domain name but that is slightly misspelled in hopes
    5·1 answer
  • What is a basic operation of computers
    13·1 answer
  • _____ view focuses on the text and content of a document, without much information on the page layout
    15·1 answer
  • Once you resize a photograph, it cannot be returned to its original size. TRUE or FALSE
    8·1 answer
  • For what purpose is keylogging software used? a. To automatically translate input to another language as the user enters data b.
    10·1 answer
  • People are starting to type in whole questions rather than specific words, which leads credence to having _____ that have this a
    14·1 answer
  • What is the function for displaying differences between two or more scenarios side by side?
    11·2 answers
  • Mention how to install antivirus software in your computer, either by following the instructions given on installation CDs or we
    6·1 answer
  • If you try to add a new item to a full stack the resulting condition is called a(n)?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!