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
Importance of software in computer
Juli2301 [7.4K]

Answer:

Computer hardware is virtually useless without computer software. Software is the programs that are needed to accomplish the input, processing, output, storage, and control activities of information systems.

Explanation:

4 0
3 years ago
Read 2 more answers
How many wires are in a standard Cat 6 cable?
Lynna [10]
I believe it is 8

Hope this helps
5 0
3 years ago
Read 2 more answers
You just realized the turn signal on your vehicle is broken,
zimovet [89]

Answer:

c

Explanation:

7 0
4 years ago
Hardy doesn't have access to a work template, which is on the network server. What should he do?
Anton [14]

He should go to a desktop computer that is attached to the network server to access it

7 0
4 years ago
Read 2 more answers
This type of program is designed to be transmitted over the internet and run in a web browser
vodomira [7]
This sounds like a web-based application because they are designed to be ran within a website, generally with Adobe Flash.
8 0
3 years ago
Other questions:
  • Assume the existence of a Window class with a function getWidth that returns the width of the window. Define a derived class Win
    15·1 answer
  • What are the elements of an autobiographical narrative similar to those of a short story?
    7·1 answer
  • A hard disk is divided into tracks which are further subdivided into:​
    11·1 answer
  • Which of the following are valid values for a boolean value in programming? (Select all that apply)
    8·1 answer
  • The “Fix a Problem” section of About.com’s PC support page provides information on Reversing Damages and (blank) plss help its t
    5·2 answers
  • The following program segment is designed to compute the product of two nonnegative integers X and Y by accumulating the sum of
    9·1 answer
  • I made Pico with a Ray Gun (Next is Dad/Tankman)<br><br> Opinons?
    11·2 answers
  • Which is an example of artificial intelligence in computers? A. multimedia software B. encryption software C. voice recognition
    6·1 answer
  • Write a program that asks the user to enter a series of single digit numbers with nothing separating them. Read the input as a C
    12·1 answer
  • which of the following can be represented by a sequence of bits. 1. An integer 2. An alphanumeric character 3. A machine languag
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!