Question
c program please For this weeks lab assignment, will convert a users binary number to its decimal equivalent. Your program should do the following: 1.
c program please
For this weeks lab assignment, will convert a users binary number to its decimal equivalent. Your program should do the following: 1. Prompt the user to enter a binary number of up to 10 digits. Any leading zeros will be ignored as long as you use %d in your scanf. Keep in mind that binary numbers consist of only 1s and 0s. You may assume that the user will not enter any input that has any number other than a 1 or a 0. 2. At this point, we are limited to using scanf to capture that input (do not use any other function that you may know about). Again, be sure to use a %d (and NOT a %i) format string with your scanf(). This lab requires that you take process the input as a single integer (not as a string or a character array). Processing the input as a string or a character array will result in a significant point deduction for this assignment. 3. Using a loop, fill up an integer array with the binary digits entered by the user. For this step, youll need to figure out how to use arithmetic operations and expressions in your loop to fill up your integer array with the correct digits. Before writing code for this step, work through a few examples on a piece of paper (yes, it is a common practice in computer science to solve a problem on paper before implementing it in a programming language). After you understand how mathematics can solve this problem, then implement your solution for this step in your 1program. 4. Using another loop, print the array back to the user (showing the binary number that they entered). 5. Using a third loop, convert that binary number to its decimal equivalent and print the result to the user. For this step, youll need to figure out how to use arithmetic operations and expressions to compute the decimal equivalent. Before writing code for this step, work through a few examples on a piece of paper to understand the mathematics involved. Once you understand how mathematics can solve this problem, then implement your solution for this step in your program. A sample run should look like the following: Enter a binary number of up to 10 digits: 100100 The binary number you entered was: 100100 The decimal equivalent of that number is: 36 NOTE: Because at this point, with what might have been covered in lecture so far, we are limited to using scanf to capture the users input, which leads to the challenge of figuring out how to determine the number of digits in the number entered by the user. You can Google this question, and you will find all different kinds of answers. The easiest one to use is a logarithmic function, like the following: numOfDigits = (log10(input)) + 1; This will return the number of digits in the input number entered by the user, ignoring any leading zeros. Once you have the number of digits, you can declare an array of that size, and continue on with figuring out steps 3-5 in the Lab Assignment above. Once youve finished test your program with various valid inputs to make sure your program is working correctly. Also, your programs I/O must match the examples above and the additional examples below. Additional Example 1: Enter a binary number of up to 10 digits: 1111000111 The binary number you entered was: 1111000111 The decimal equivalent of that number is: 967
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started