Question: In C:Write a program that can determine whether a user input is a binary number or not. (1, 2, 3, 8, 13) Write a program

In C:Write a program that can determine whether a user input is a binary number or not. (1, 2, 3, 8, 13) Write a program that accomplishes all of the following:

Greets the user and informs them that the program will determine whether an input from the user is a valid binary number or not (e.g., consisting of only 0s and/or 1s).

Accept an integer input from the user. Assume that the user provides a valid numeric input that will fit in the standard int type. However, check to make sure the input was a positive number - for our purposes, any negative integer input is not a binary number.

Use a loop to check all of the digits of the given input to determine that they are either 0 or 1 (Hint: You may want to use the modulus and division operators to process the digits one-by-one).

If all digits were either 0 or 1, print a message to the user stating that the input was a valid binary number. Otherwise, print a message stating that the input was not a valid binary number.

Test your program thoroughly. Make sure to at least the following inputs and verify the results:

0: binary

1: binary

01: binary

21001: not binary

-1011: not binary

123: not binary

10101: binary

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!