Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

Students also viewed these Databases questions

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago