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
Working with cell addresses The address of a cell in Google sheets can be specified in two ways: either as a letter-number pair like C5, or as a pair of numbers like "row 5, column 3". Some formulas may be easier to specify on one way or the other, so it's useful to know how to convert from one form to the other and back. ROW() and COLUMN() take addresses in A1 format and return the number of the row and column respectively. ADDRESS() takes numeric row and column inputs and returns the address in A1 format. It also has an option argument to specify the relativity of the addresses: 1 (the default) returns absolute addresses; 2, 3, and 4 return row absolute, column absolute, and relative addresses respectively. In this chapter you'll be working with Indian butterfly data from Singh and Pandey. Instructions In column H, get the row numbers of the Locality column. In column I, get the column numbers of that column. In column J, convert columns H and I back to addresses in $A$1…
A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a fish is swimming past if:there are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we will call "Fish Rising"), orthere are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we will call "Fish Diving"), orthere are four consecutive depth readings which are identical (which we will call "Constant Depth").All other readings will be considered random noise or debris, which we will call "No Fish."Create a Python program called "fishfinder_firstname_lastname" that takes 1 input of string of 4 numbers separated with comma. Your program must display "Fish Rising", "Fish Diving.", "Fish At Constant Depth" or "No Fish".Example:30,10,20,20 Must display No…
We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different “digits" {0,1, ...,9}. Sometimes though it is useful to write numbers hexadecimal or base 16. Now there are 16 distinct digits that can be used to form numbers: {0, 1,...,9, A, B, C, D, E, F}. So for example, a 3 digit hexadecimal number might be 2B8. Assume that digits and letter can be repeated. a. How many 4-digit hexadecimals are there in which the first digit is E or F? b. How many 5-digit hexadecimals start with a letter (A-F) and end with a numeral (0-9)?
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