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
vazorg [7]
3 years ago
5

Write a recursive function that returns the number of 1 in the binary representation of N. Use the fact that this is equal to th

e number of 1 in the representation of N/2, plus 1, if N is odd.
Computers and Technology
1 answer:
givi [52]3 years ago
7 0

Answer:

#here is code in python

# recursive function that counts the number of 1's

def bin_count(num):

   #base condition

   if num==0:

       return (0)

   elif num == 1:

       return (1)

   else:

       #recursive call

       return bin_count(num//2)+bin_count(num%2)

#read a number

num=int(input("enter a number:"))

#call the function

print("number of 1's is:",bin_count(num))

Explanation:

Read a number from user and call the function bin_count() with parameter num. In the function, if num=0 then it will return 0.If num is 1 then return 1 else it will count the number of 1's inn the binary representation of the number and return the count.

Output:

enter a number:63

number of 1's is: 6

You might be interested in
Describa las características más importantes de cada procedimiento,difencias entre si Procedimiento Bessemer Procedimiento Sieme
Igoryamba

Answer:

A continuación se explican cada una de las características más importantes de cada  horno:

Explanation:

<u>Procedimiento Bessemer:</u>

En este horno el oxígeno del aire quema el silicio y el manganeso que se encuentra en la masa fundida y los convierte en óxidos., luego el oxígeno comienza a oxidar el carbono.Luego finalmente el hierro se oxida,ya en este punto sin haber oxígeno ahora se añade a esa masa hierro carbono y finalmente manganeso.

<u>Procedimiento Siemens Martin:</u>

A 1800 º C funde la chatarra y lingotes de arrabio solidificado bajo la llama producida en la combustión; se eliminan las impurezas y se consiguen aceros de una gran calidad para fabricar piezas de maquinaria. Este tipo de horno tiene una gran uso en el mercado  ya que pueden fundir latones, bronces, aleaciones de aluminio, fundiciones y acero.

<u>Procedimiento Horno electrico:</u>

Trabaja a una temperatura de  1930 °C, se puede controlar eléctricamente, pueden contener hasta 270 toneladas de material fundido. También en estos hornos se inyecta oxígeno puro por medio de una lanza.

8 0
4 years ago
The while loop is a pre-test loop? TRUE OR FALSE
mihalych1998 [28]
True

Hope I helped! 

Let me know if you need anything else!

~ Zoe
5 0
4 years ago
Read 2 more answers
What computer would I need to set up my oculus quest 2 aka make my oculus quest 2 link to a computer?
Neko [114]

Answer:

Any computer would do as long as it isn't slow and has a good fps to render the games you plan to connect with. Make sure you have the correct cable though.

5 0
3 years ago
Read 2 more answers
Which is a method used with arrays?<br><br> find<br><br> index<br><br> insert<br><br> sort
Furkat [3]

Answer:

Index

Explanation:

Got it right e2020

4 0
3 years ago
Which of the following is not an operating system a) boss b) window xp c) linux d) bindux​
zmey [24]

Answer:

boss is not an os

Explanation:

boss is a former of Linux hope this helped

5 0
3 years ago
Other questions:
  • The superintendent forbade the students to bring their books and copies in the exam hall. (into direct speech)​
    10·1 answer
  • Which computer tools allow you to communicate with coworkers, family,and friends
    8·1 answer
  • Which AWS service is a managed service that makes it easy to set up, operate, and scale a relational database in the cloud?​
    9·1 answer
  • The word count of the active document is typically displayed on the ________.
    15·1 answer
  • True or false: its okay to sometimes compromise our values in order to resolve a conflict
    15·1 answer
  • Why does esherick say the name of the boxer rebellion in inaccurate
    5·1 answer
  • An AM index between 0 and 1 indicates what? a. the AM signal is very small and will not be detected by the receiver b. distortio
    12·1 answer
  • a document contains a list of items that appear in no particular order. what is the best way to format the list
    5·1 answer
  • To cope with the uncertainty about how their pages will be viewed, many web page designers opt to use _________ units, which are
    13·1 answer
  • Which of the following BEST describes a permissive software license?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!