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
Factors to consider while selecting a software to use​
luda_lava [24]
You need to consider what exactly you will be using the software for, there are many different softwares and they all have different purposes.
6 0
2 years ago
in java how do i Write a Java program that takes ten numbers as input to calculate and print the average of the numbers.
Andrei [34K]

Answer:

You could just use a code library.

Explanation:

8 0
3 years ago
What is output?
Alex777 [14]

Answer:

The output of this question is 21. As show in the image

The explanation is given in below

Explanation:

Let first write the question

C=1

sum = 0

while(C<10):

C=C+3

sum=sum + C

print(sum)

Now Focus on

while(C<10):

C=C+3

sum=sum + C

The value of C is initially 1

C=1+3

Sum= 0+4

In second loop the value of C will become 4

c=4+3

sum=4+7

In third loop the value of C will be 7

c=7+3

sum=11+10

so the answer is 11+10=21

7 0
2 years ago
Hotels and motels that are part of a ________ share a centralized reservation system and a common image, logo or advertising slo
hoa [83]
It is company , I think .
8 0
3 years ago
Electronic components in coputers process data using instructions, which are the steps that tell the computer how to perform a p
Dominik [7]

Answer:

True

Explanation:

  • True, the electronic components perform the tasks that are given to the computer.
  • The computer is made up of nothing but the electronic components like Transistors, Circuits etc.  
  • Electronic components are the building blocks of the computer.
  • So essentially all the tasks performed by the computer are actually performed by the electronic components inside it.
  • So it can be understood that the tasks that are given to the computer are performed by the electronic components. They perform the tasks with the instructions given to the computer.  
  • There also special electronic components designed to read, write and perform the tasks given to the computers.
  • The electronic components comprise of the circuits, transistors, resistors and capacitors.
3 0
3 years ago
Other questions:
  • Chdtp aoxophg gr72 ae9&gt;3 zqqz
    12·1 answer
  • Jackson is teaching a class the concept of the binary number system. Which term will he use to refer to the leftmost bit of a bi
    7·1 answer
  • Description A data retrieval tool that finds specified data within a database A collection of records All of the fields for a si
    7·1 answer
  • MULTIPLE CHOICE:
    15·1 answer
  • Why are free web based providers so popular?
    12·1 answer
  • The first page of a website is what?​
    5·2 answers
  • (a) Write a program which calculates and displays the obtained marks, percentage in six subjects and assigns grades based on per
    6·1 answer
  • 100 POINTS!!!!!!
    7·2 answers
  • I have this questions i need to make it in a report format pages of atleast 3 pages and maximum of 5 pages​
    7·1 answer
  • Which of the following is the best description of an ip address?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!