Question: C CODE Write a program to ask the user to input a binary number (largest is 1111111111), such as 1001 which equals to decimal number

C CODE

Write a program to ask the user to input a binary number (largest is 1111111111), such as 1001 which equals to decimal number 9. Use int variable to store the binary number. Then, convert the binary number into decimal integer format and print the decimal integer out. You should check whether the number the user input is a binary number or not, if not, you should keep asking for correct input.

C CODE Write a program to ask the user to input a

(TIP: b, bn-ibn-2-.. b2b1=bn * 2-1 th-1+2n-2 + + bz * 21 +ht 20 , e. g. 1001 = 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20-9 . Use mod .962, and divide ./10 alternatively to decompose the binary mumber, for example translate the binary number 101 nary number 1 2. 3. decimal num =0; 101 % 2 = 1;decimal num t l*20, 101 / 10-10; 10962-0; decimal num += 0 * 2^1,10/10=1; 1 %2-1; decimal num= 1 * 22 i/10-0: Decimal num-5. End. 4. 5, Use %10, in each iteration to test teat whether the input number is binary or not) Example Hints and Inputs: (purple texts are what the program should print on the screen to instruct the users, the black texts are what the users type in) Input a binary number: 1002 Illegal input, please input again: 1111 Example Outputs The decimal number of 1111 is 15

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!