Question: Write a C++ program that reads a positive integer and prints all of its binary digits (in reverse order). Print the number % 2, then

Write a C++ program that reads a positive integer and prints all of its binary digits (in reverse order). Print the number % 2, then replace the number by number / 2. Keep going until the number is 0.

Validate the input. Do not accept a negative integer.

Sample run of program:

Enter a positive integer:

> -2

Invalid input! Try again:

> 20

Your number in binary in reverse order is:

0

0

1

0

1

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!