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
vivado [14]
3 years ago
12

Write a program that asks the user to enter a positive integer that represents a number in the decimal system and then displays

the binary representation of the number. Your solution must include at least the following function: decimalToBinary(number): a recursive function that takes a positive integer number (in decimal) as its parameter and returns a string with it's binary representation. g
Computers and Technology
1 answer:
Maru [420]3 years ago
3 0

Answer:

In Python:

def decimalToBinary(num):

   if num == 0:

       return 0

   else:

       return(num%2 + 10*decimalToBinary(int(num//2)))

       

decimal_number = int(input("Decimal Number: "))

print("Decimal: "+str(decimalToBinary(decimal_number)))

Explanation:

This defines the function

def decimalToBinary(num):

If num is 0, this returns 0

<em>    if num == 0: </em>

<em>        return 0 </em>

If otherwise

   else:

num is divided by 2, the remainder is saved and the result is recursively passed to the function; this is done until the binary representation is gotten

       return(num%2 + 10*decimalToBinary(int(num//2)))

       

The main begins here.

This prompts the user for decimal number

decimal_number = int(input("Decimal Number: "))

This calls the function and prints the binary representation

print("Decimal: "+str(decimalToBinary(decimal_number)))

You might be interested in
What are the answers to 14 and 15
RoseWind [281]
The answer to 14 is c and the answer to 16 is a
6 0
4 years ago
Explain the difference between using the int type and the double type for numbers.
MaRussiya [10]
They have different semantics, <span>addition to having different semantics from </span>double<span>, </span>int<span> arithmetic is generally faster, and the smaller size (32 bits vs. 64 bits) leads to more efficient use of caches and data transfer bandwidth.....
Did That Help You In Anyway </span>
6 0
4 years ago
A professor copies one article from a periodical for distribution to the
MariettaO [177]
Yess I think I’m not sure
4 0
4 years ago
Read 2 more answers
What are minimum computer requirements for a software program?
Bumek [7]
<span><span>Operating system: Windows 2000/XP
</span><span>CPU: Pentium 4 1.5 GHz or Athlon XP 1500+ processor or higher
</span><span>Memory: 384 MB RAM</span></span>
8 0
4 years ago
Which option helps you choose the design of a slide in a presentation A) slide layout b) shapes c) animation d) slide transition
mihalych1998 [28]

Answer:

B) slide layout

Explanation:

Slide layout, since you can choose what type of design you want, I'm guessing this is for power point.

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following explains why computers can be used in accounts payable? Computers can use random steps to identify the du
    7·2 answers
  • How many bones are in a human body
    7·2 answers
  • Which of the following statements is​ FALSE? A. Security is a huge concern for nearly all organizations with private or propriet
    14·1 answer
  • What is the advantage of using a high-level language over machine language for writing computer programs?
    12·2 answers
  • Uploading is the process of transferring existing content stored on a server or other computer or device to your device via a ne
    8·1 answer
  • One way to describe the note-taking tool eNotes is to call it an electronic notebook. electronic sticky note. online web clippin
    5·2 answers
  • Want summmmmmmm bec i do lol
    9·1 answer
  • Which of the following is NOT a reason to use cryptography?
    5·2 answers
  • Define the html code to insert a heading
    14·1 answer
  • Which type of database program is Microsoft Access 2016?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!