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
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Programming in C
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Computer Systems: A Programmer's Perspective (3rd Edition)
Experiencing MIS
Starting Out with Python (3rd Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- In the example below, the sum of the fourth powers of each digit that forms the 4-digit numbers gives the number itself: 1634 = 14 + 64 + 34 + 44 8208 = 84 + 24 + 04 + 84 9474 = 94 + 44 + 74 + 44 And sum of these numbers is 1634 + 8208 + 9474 = 19316. Find the sum of all numbers that can be written as the sum of the fifth forces of their numbers. (P.s.: You have to done it by C++)arrow_forwardIn the real world, functions are mathematical representations of input-output situations. A vending machine is one such example. The input is the money combined with the selected button. The output is the product. Here is another example: The formula for converting a temperature from Fahrenheit to Celsius is a function expressed as: C = (5/9)*(F - 32), where F is the Fahrenheit temperature and C is the Celsius temperature. If it is 77 degrees Fahrenheit in Phoenix Arizona, then what is the equivalent temperature on the Celsius thermometer? Our input is 77. C = (5/9)*(77 - 32) C = (5/9)*(45) C = 25 The equivalent temperature is 25 degrees Celsius. To complete the Discussion activity, please do the following: Choose your own function or choose from the list below and then provide a unique example of a function and evaluate the function for a specific input (like the example above). Arm length is a function of height. The circumference of a circle is a function of diameter. The height of…arrow_forwardIn python programming, i) In the year 1752, the Gregorian Calendar was adjusted. Eleven days were dropped from the month of September, resulting in a year with only 354 days! Historically, we know the days of the week in that year... but assuming we don't, what is the probability that the year had 51 Sundays?arrow_forward
- Information is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible (nlogn or n at best, no n2) and runtime should be under 1 second. Apply dynamic programming. Do not use recursion. Make sure ALL test cases return expected outputs. Output FormatFor each query, output one line containing an integer Dn. The number must be output mod (109 + 7). Sample Input 0:501234 Sample Output 0:10129 Edge Case: (to test against runtime and timeout error)300000 (number of queries)300000300000300000300000...and so on until there are 300,000 of them The actual code: def solve(n): MOD = 1000000007 # compute and return answer here q = int(input().rstrip()) outs = [] for i in range(q): n = int(input().rstrip()) outs.append(solve(n)) print("{}".format("\n".join(list(map(str,outs)))))arrow_forwardPlease answer it in Python Suppose we play a game where each round takes place in the following way: first, we roll a dice, and its result gives the number of points at stake. Then, the player can, if he wishes, trigger his bonus "double account" or his bonus "triple account". Then, the player answers a number of questions, and calculates his percentage of correct answers. The points awarded to the player for that round are then calculated based on the percentage of correct answers and the number of points in play rounded to the nearest integer (for example, with 50% correct answers and 6 points in play, the player gets 3 points; with 45% correct answers and 8 points in play, the player gets 4 points). Finally, this number of points is possibly multiplied by two or three if the corresponding bonus has been used. Write a function points_match that takes as an argument the percentage, the number of points at stake, and as an optional argument the multiplier (which is worth 2 in a double…arrow_forwardSolve in python: When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustment can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by dividing all values by the largest value. The input begins with an integer indicating the number of floating-point values that follow. 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: 5 30.0 50.0 10.0 100.0 65.0 the output is: 0.30 0.50 0.10 1.00 0.65 The 5 indicates that there are five floating-point values in the list, namely 30.0, 50.0, 10.0, 100.0, and 65.0. 100.0 is the largest value in the list, so each value is divided by 100.0.arrow_forward
- Take note that each product is distinct and can easily be identified as a winning number.Write the code for generating a "score" for each row. If a cell is left blank, we assume its value is 1, so multiplying it has no effect (any number multiplied by 1 is the number itself). Alternatively, as shown in the code below, simply do not multiply the value of that cell at all.arrow_forwardCorrect answer will be upvoted else downvoted. How about we call a positive integer n customary if in the decimal documentation every one of its digits are something very similar. For instance, 1, 2 and 99 are conventional numbers, however 719 and 2021 are not normal numbers. For a given number n, track down the number of common numbers among the numbers from 1 to n. Input The main line contains one integer t (1≤t≤104). Then, at that point, t experiments follow. Each experiment is characterized by one integer n (1≤n≤109). Output For each experiment output the number of common numbers among numbers from 1 to n.arrow_forwardInformation is present in the screenshot and below. Based on that need help in solving the code for this problem in python. The time complexity has to be as less as possible. Apply dynamic programming and memoization. Do not use recursion. Make sure ALL test cases return expected outputs. Hint: Approach the problem with 2D Dynamic Programming. Output FormatOutput one line containing a single integer containing the answer as described in the problem statement. This number must be output mod 109 + 7. Sample Input 0:3 9357 Sample Output 0:5 Sample Input 1:3 23151615 Sample Output 1:4 Sample Input 2:3 6123 Sample Output 2:8 The actual code: def solve(n,c,ws): # compute and return answer here # place 2 nested for loops here MOD = 1000000007n, c = list(map(int,input().rstrip().split(" ")))ws = [int(input().rstrip()) for i in range(n)]print(solve(n,c,ws))arrow_forward
- Please answer it in Python Offer a program that knows how to find the solution of the jackpot price game in a way effective. it's up to you to choose a number at random, and it's up to your program. to guess it. You must write him 'g' if the number he guessed is too large, 'p' if the number is too small and 'b' if he guessed the right number. The number of trials is not limited. The program should always be able to guess the right number fast enough Example 1: Think of a number and I'll try to guess! Ready? Press Enter... Hmm.. Is it 15? p Hmm.. Is it 35? g Hmm.. Is it 31? g Hmm.. Is it 24? g Hmm.. Is it 20? g Hmm.. Is it 19? g Hmm.. Is it 17? p Hmm.. Is it 18? b I won! Example 2: Think of a number and I'll try to guess! Ready? Press Enter... Hmm.. Is it 4? p Hmm.. Is it 69? g Hmm.. Is it 49? g Hmm.. Is it 7? p Hmm.. Is it 19? p Hmm.. Is it 38? g Hmm.. Is it 25? g Hmm.. Is it 20? b I won! Example 3: Think of a number and I'll try to guess! Ready? Press Enter... Hmm.. Is it 46? g Hmm..…arrow_forwardSuppose you save $100 each month in a savings account with annual interest rate 3.75%. Thus, the monthly interest rate is 0.0375/12 = 0.003125. After the first month, the value in the account becomes 100 * (1 + 0.003125) = 100.3125, after the second month, the value in the account becomes (100 + 100.3125) * (1 + 0.003125) = 200.938, after the third month, the value in the account becomes (100 + 200.938) * (1 + 0.003125) = 301.878 and so on. Write a Java program that prompts the user to enter a monthly saving amount and displays the account value after the sixth month. (You will use a loop to simplify the code and display the account value for any month.) Sample Output:Enter the monthly saving amount: 100After the first month, the account value is 100.3125After the second month, the account value is 200.9384765625After the third month, the account value is 301.8789093017578Note: The computation should be until 12 months.arrow_forwardFive members of an obesity club want to know how much they have lost or gained weight since the last time they met. To do this, they carry out a weighing ritual where each one is weighed on ten different scales in order to have a more accurate average of their weight. If there is a positive difference between this average weight and the weight of the last time they met, it means that they gained weight. But if the difference is negative, it means that they lost weight. What the problem requires is that for each person a sign is printed that says "went up" or "under" and the amount of pounds Write a program in c++ using for, do while or while. Initial weights 230, 240, 180, 300 and 350. Do not use arraysarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr