Computer Science: A Structured Programming Approach Using C, Third Edition
3rd Edition
ISBN: 9780534491321
Author: Behrouz A. Forouzan, Richard F. Gilberg
Publisher: Course Technology, Inc.
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 48PS
Program Plan Intro
To create a
Program Plan:
Create a program that writes a function named day_of_week.
The code takes the user input between 0 and 6.
The code displays the corresponding week's day. For example, Sunday(0), Monday(1), Tuesday(2), etc.
The code will work, in such a way, that Sunday is the 1st week’s day.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The first and second numbers in the Fibonacci sequence are both 1. After that, each subsequent number is the sum of the two
preceding numbers. The first several numbers in the sequence are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, etc. Write a function named
fib that takes a positive integer parameter and returns the number at that position of the Fibonacci sequence. For example fib(1) =
1, fib(3) = 2, fib(10) = 55, etc. Your function does not need to print anything out - just return a value.
For example, your function could be called like this:
term = fib(17)
You cannot use recursion, since we haven't covered that technique. That means that for this assignment you cannot have your
function call itself. This includes indirect recursion, such as one function calling a second function that calls the first function. You
must use a loop to step through the sequence - do not use the golden ratio to directly calculate the value.
When it is 8:00 in Lubbock,
• It is 9:00 in New York
• It is 14:00 in London
• It is 15:00 in Cairo
• It is 16:00 in Istanbul
• It is 19:00 in Hyderabad
• It is 22:00 in Tokyo
Write a function that reports the time in
New York, London, Cairo, Istanbul,
Hyderabad, and Tokyo based on the time
in Lubbock. Use a 24-hour time format.
Include error trapping that:
1. Issues a message like "Please Enter A
Number from 00 to 23" if the first
input is numeric but outside the range
of [0,23].
2. Takes any numeric input for "Lubbock
time" selection , and forces it into an
integer.
3. Issues an appropriate message if the
user's selection is non-numeric.
Test your function for these times:
• 8:00
• 15:00
• 0:00
In [ ]:
# script goes here
Write a function that computes the average of the digits in an integer. Use the following function header:
double averageDigits(long n)
Chapter 5 Solutions
Computer Science: A Structured Programming Approach Using C, Third Edition
Ch. 5 - Prob. 1PSCh. 5 - The expression in a selection statement can have...Ch. 5 - Each labeled statement may identify one or more...Ch. 5 - The character classification functions are found...Ch. 5 - Prob. 5PSCh. 5 - The logical operator is true only when both...Ch. 5 - Prob. 7PSCh. 5 - Two-way selection is implemented with the ...Ch. 5 - Prob. 9PSCh. 5 - Which of the following statements creates the...
Ch. 5 - There are two different ways to implement a...Ch. 5 - Which of the following statements about switch...Ch. 5 - Which of the following statements about the...Ch. 5 - Prob. 14PSCh. 5 - Prob. 15PSCh. 5 - If x=0,y=5,z=5, what is the value of x, y, and z...Ch. 5 - If x=3,y=0,andz=4, what is the value of the...Ch. 5 - Simplify the following expressions by removing the...Ch. 5 - Prob. 19PSCh. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=2,y=1,andz=1, what is the value of...Ch. 5 - If originally x=1,y=3,andz=0, what is the value of...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Write an if statement that will assign the value 1...Ch. 5 - Prob. 36PSCh. 5 - Write the code to add 4 to an integer variable,...Ch. 5 - Prob. 38PSCh. 5 - Write the code to print either zero or not zero...Ch. 5 - If the variable divisor is not zero, divide the...Ch. 5 - Prob. 41PSCh. 5 - Rewrite the following code using one if statement:...Ch. 5 - Rewrite the following code fragment using one...Ch. 5 - Write a code fragment that tests the value of an...Ch. 5 - Prob. 45PSCh. 5 - Prob. 46PSCh. 5 - Write a function called smallest that, given three...Ch. 5 - Prob. 48PSCh. 5 - Write a function called month_of_year that, given...Ch. 5 - Write a function called parkingcharge that, given...Ch. 5 - Prob. 51PSCh. 5 - Complete the incremental implementation of Program...Ch. 5 - Write a program that determines a student's grade....Ch. 5 - Prob. 54PSCh. 5 - Given a point, a line from the point forms an...Ch. 5 - Prob. 56PSCh. 5 - Write a program that asks the user to enter the...Ch. 5 - Prob. 58PSCh. 5 - This program is a simple guessing game. The...Ch. 5 - Write a program that, given a person's birth date...Ch. 5 - Write a program that calculates the change due a...Ch. 5 - Write a menu-driven program that allows a user to...Ch. 5 - Write a program that tests a user-entered...Ch. 5 - Write a program to compute the real roots of a...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy: KE = 1⁄2 mv2 The variables in the formula are as follows: KE is the kinetic energy in joules, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.Write a function named kineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The function should return the amount of kinetic energy that the object has. Demonstrate the function by calling it in a program that asks the user to enter values for mass and velocity.arrow_forwardFor each of the following functions, indicate how much the function’s value will change it its argument is increased Triple.arrow_forwardThe value of a global constant can only be changed within a function. True or falsearrow_forward
- . The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for the first 300 kwh 8 cents per kwh for the next 300 kwh (up to 600 kwh) 6 cents per kwh for the next 400 kwh (up to 1,000 kwh) 5 cents per kwh for all electricity used over 1,000 kwh Write a function to compute the total charge for each customer. Write a main function to call the charge calculation function using the following data: Customer Number Kilowatt-hours Used 123 725 205 115 464 600 596 327 … … The program should print a three column chart listing the customer number, the kilowatt hours used, and the charge for each customer. The program should also compute and print the number of customers, the total kilowatt hours used, and the total charges.arrow_forwardWrite a function that triples a numberarrow_forwardWrite a function that determines if a number is prime. Use this function in a program that determines and prints all the prime numbers between 1 and 10,000. Do the required commented changes in the following program codearrow_forward
- Assume on a planet called “Chocolatey”, 1 month = 20 days and 1 year = 240 days = 12 months. Write a function Days that takes 2 arguments: a start date and the last date. Then calculates the number of days between these two dates(inclusive) and returns it to the function call. Assume, the start and last date will be given in dd/mm/yyyy format. ================================ Function Call1: function_name("3/8/2018", "12/12/2020") Sample Output1: 570 ================================ Function Call2: function_name("3/8/2020", "12/12/2020") Sample Output2: 90 ================================ Function Call3: function_name("3/8/2018", "3/9/2020") Sample Output3: 501 ================================ Function Call4: function_name("3/8/2018", "10/8/2020") Sample Output4: 488arrow_forwardWrite a function that returns the greatest common divisor of 2 integers.arrow_forwardWrite a function called print_multiples that takes in a number and prints out 10 multiples of that number. For example, the multiples of 10 are 10, 20, 30, 40, 50, 60, 70, 80, 90, and 100. BIU A- IE三 三 x x,三E 12pt Paragraph Previous Nextarrow_forward
- Because of the outbreak of the Coronavirus (COVID-19), visitors from infested countries and regions have to be quarantined for 14 days which is 14 X 24 X 60 = 20160 minutes! Write a function Min2DHM(minutes) that takes the number of minutes as a parameter and converts that number of minutes into a specific format below: Day(s): Hour(s): Minutes(s) Note: You can assume the number of minutes is between 0 and 20160 and here is the expected output of your function.arrow_forwardFor each of the following functions, indicate how much the function's value will change if its argument isincreased fourfold. log2n n3 2narrow_forward# Write a function called ex3(n) which# 1. accepts as an input parameter an integer between 1 and 100# 2. Calculates and print the mersenne primes between 1 and this number# See en.wikipedia.org/wiki/Mersenne_prime for details# 3. Invoke ex3(16) to print resultsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
functions in c programming | categories of function |; Author: Education 4U;https://www.youtube.com/watch?v=puIK6kHcuqA;License: Standard YouTube License, CC-BY