
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question

Transcribed Image Text:Programing C
Just with #include<stdio.h>
Calculate Binary Number
Given a number, your program will calculate its binary equivalent. As shown in the figure below, your program
will ask the user for a number, then print out the resulting binary.
Guidelines:
• First, scan the number in your main function.
• Next, from main, send this number to function aaa and determine how many binary digits you will need to
represent the decimal number in binary. In other words, if the user inputs 26, how many times can you divide 26
by 2 and keep dividing it by two until you reach 0? In the representation below, I show that I needed 5 divisions
for 26 to reach 0 (notice I ignored the 0.5 for 6, 1 and 0).
26
= 13 →
2
13
6.
3
= 3 →
2
Using this logic, you should be able to determine how many binary digits you will need for any decimal number
the user gives you. Once your function determines the number of binary digits that you will need, it should
return this value back to main.
• Then, in main, you will call function bbb. You will send two values, the number of digits determined in
function aaa and the decimal number inputted by the user. Then, you will create a temporary array; can you
guess what its length will be?
• Once you declare your temporary array, you will use it to store the remainders of your divisions (do you
remember the process of converting from decimal to binary?). To do so, you will need the modulo operator..
• If we look at the example of 26 in the figure below, we can see that its binary number is 11010. Well, at the
end of function bbb your array should be the exact opposite of this binary number. At the end of function bbb,
the values inside your array should be 01011. Thus, you will need a third function (function ccc), to which you
will send this array and print the values backwards. Notice that you will also have to send the length of your
array to function ccc.
• Functions bbb and ccc should not return anything.
What is your decimal number? 26
We will need 5 binary digits.
Decimal Number is: 26
Binary Number is: 11010
What is your decimal number? 81
We will need 7 binary digits.
Decimal Number is: 81
Binary Number is: 1010001
What is your decimal number? 103
We will need 7 binary digits.
Decimal Number is: 103
Binary Number is: 1100111
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Similar questions
- First write a function f to generate and return a random number between 0 to 100 In the main function, you keep calling function f until the returned value is less than 10 Then you should print out how many times the function f has been called. Note that every time f will only return a single random number, and the declaration of f is as follows: int f() For instance, if f returns 23, 89, 10, 1, then your program should print 4 on the screen. C++ language Hint 1. You can implement the function using different methods, like the static variable Hint 2. You can use the modular operator to shrink the generated random value, i.e., random() % 101 will guarantee the result is between 0 and 100.arrow_forwardOne lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print (f'{your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function: def laps_to_miles (user_laps) 461710.3116374.qx3zqy7 LAB ACTIVITY 7.8.1: LAB: Track laps to miles 1 # Define your function here 2 3 if __name__ 4 main.py == '__main__': #Type your code here. Your code must call the function. 0/10 Load default template...arrow_forwardYou hired three programmers and you (hopefully) pay them. Create a function that takes three numbers (the hourly wages of each programmer) and returns the difference between the highest-paid programmer and the lowest-paid. Example: programmers(510, 193, 42) → 468 WRITE IN PYTHON PLEASEarrow_forward
- Write a complete C program to calculate the perimeter and area of a triangle with 3 sides namely a, b, and c. The sides will be given as inputs by the user. The program will be executed at least once, and repeat as long as user wish to calculate again. There are a total of 5 functions: • Function 1: o This function will display the menu options that the user can choose (to calculate perimeter or area of a triangle). • Function 2: o This function will calculate the perimeter of a triangle o Accepts the sides of triangle as parameter o Formula: perimeter = a + b + c o Return the result back to the caller. • Function 3: o This function will calculate the area of a triangle o Accepts the sides of triangle as parameter o Formula: area = 5 (s – a)(s – b)(s – c), where s = (a + b + c)/2 o Return the result back to the caller. Function 4: o This function will get the sides of triangle from user. o Ask user for option on what s/he would like to calculate. o Based on the option (Use switch case…arrow_forwardOne lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print (f' {your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function: def laps_to_miles (user_laps) 461710.3116374.qx3zqy7 LAB ACTIVITY 1 # Define your function here 21 3 00 Jo UAWN P 4 if ___name__ 5 6 7.8.1: LAB: Track laps to miles 7 8 main.py '__main__': # Type your code here. Your code must call the function. 8/10 Load default template...arrow_forwardWrite a section of Python code (not an entire function) that: Asks the user to input a number between 1 and 10.You do not need to validate the user's input. Displays the message, "This is a low number." if the number is from 1 to 5. Displays the message, "This is a high number." if the number is from 6 to 10. Write the Python code as efficiently as possible.arrow_forward
- Write a python code: Example02 Input:2250Function Call:function_name(2250)Output:6 years, 2 months and 0 daysarrow_forwardWrite a program that reads in two numbers and stores them into two variables a and b respectively. These values should then be passed into a function that swaps the values stored in the two variables (hint: use a temporary local variable). The values of the two variables should then be printed out (but not in the function where they are swapped). Note: you should use separate functions for each of the major steps in this program (i.e. input, processing, output). Remember, if you wish to pass two values out of a function, you will need to use pass by pointer parameters.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education