Question: By repeatedly applying the mapping n n / 2 ( where / denotes integer division ) , any positive number n will eventually reach 0

By repeatedly applying the mapping nn/2
(where /
denotes integer division), any positive number n
will eventually reach 0
. Write a function div_mapping that repeatedly applies this mapping to a given number n
until the number becomes 0
. At each step, output "1" and a space if n
is odd and "0" and a space if n
is even. When n
becomes 0
, output "end" (with no newline). For example, given the number n=5
, your function should output "101 end".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!