Write a program to ask the user to input a binary number (largest is XXXXXXXXXX), such as 1001 which equals to decimal number 9. Use int variable to store the binary number. Then, convert the binary...

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. Name your file Hw3 a3 code.c. (TIP: binary number bnbn-1bn-2 b2bibn*21-1b-1 22+b2 21 + bi* 20 , e.g. 1001 = 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20-9 . Use mod %2, and divide ‘/10' alternatively to decompose the binary number, for example translate the binary number 101: 1. 2. 3, decimal num-0; 101 % 2-1; decimalnum += 1 * 20; 101 / 10-10; 10 % 2-0; decimal num += 0 * 2^1 ; 10 / 10-1; - 1 * 212: 1 /10 0 4. 1 % 2-1; decimal num 5. Decimal num=5. End Use ‘%10' in each iteration to test teat whether the input number is binary or not.)

Dec 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here