Programming in C
Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 8, Problem 2E

In certain applications, particularly in the financial area, it is often necessary to calculate the number of elapsed days between two dates. For example, the number of days between July 2, 2015, and July 16, 2015, is obviously 14. But how many days are there between August 8. 2014, and February 22, 2015? This calculation requires a bit more thought.

Luckily, a formula can be used to calculate the number of days between two dates. This is affected by computing the value of .N for each of the two dates and then taking the difference, where N is calculated as follows:

N

where:

f if month <= 2

otherwise

g if month <= 2

otherwise

As an example of applying the formula, to calculate the number of days between August 8, 2004, and February 22, 2005, you can calculate the values of N1 and N2 by substituting the appropriate values into the preceding formula as shown:

N1

N2

Number of elapsed days = N2 – N1

= 732,441 – 732,239

= 202

So the number of days between the two dates is shown to be 202. The preceding formula is applicable for any dates after March 1, 1900 (1 must be added to N for dates from March 1, 1800, to February 28, 1900,and 2 must be added for dates between March 1, 1700, and February 28, 1800).

Write a program that permits the user to type in two dates and then calculates the number of elapsed days between the two dates. Try to structure the program logically into separate functions. For example, you should have a function that accepts as an argument a d structure and returns the value of .N computed as shown previously. This function can then be called twice, once for each date, and the difference taken to determine the number of elapsed days.

Blurred answer
Students have asked these similar questions
Use following series to do the given task; 135 79 11 13 15 1719 21 23 25 27 29 31 ... Given the number N of odd numbers in a certain line, your task is to determine the sum of the last three numbers of that line. For example N = 5 means, the third line, the last three numbers are 13, 15 and 17. The summation of these three numbers is 45. InputThe first line tells the number of test cases. From the next line, the input is a sequence of lines, one odd number N (1 < N <1000000000) per line. OutputFor each input line write the sum of the last three odd numbers written in that line of series with N numbers.
What do you think will happen if you use a negative number as the secondparameter in the round function? For example, what should be the resultof round(314 .159265, -1) ? Explain the rationale for your answer. Afteryou've written your answer, consult the Python documentation or try outsome examples to see what Python actually does in this case.
vvvHarry has a big wall clock, that got hit while he was playing. Now, the minute hand doesn't rotate by the angle 2π/3600 each second, but now it moves according to different angle x. You can assume that coordinates of the centre of the clock are (0, 0) and the length of the minute hand is l. One endpoint of the minute hand is always located at the clock centre; the other endpoint is initially located at the point (0, l). One second later, Harry observes that this endpoint is at distance d above the x-axis, i.e., the y-coordinate of this endpoint is equal to d. Harry is curious about where the minute hand will be (specifically, its y-coordinate) after t seconds. Because t can be very large, Harry can't wait for that moment. Please help him to write a python code that prints a single line containing the output.Input: 4 2 2Output4Harry has a big wall clock, that got hit while he was playing. Now, the minute hand doesn't rotate by the angle 2π/3600 each second, but now it moves according…
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY