Question: Compose a program dayOfWeek that accepts a date as input and writes the day of the week on which that date falls. Your program should
Compose a program dayOfWeek that accepts a date as input and writes the day of the week on which that date falls. Your program should ask the user for three values: m (month), d (day), and y (year). For m use 1 for January, 2 for February, and so forth. For output write 0 for Sunday, 1 for Monday, 2 for Tuesday, and so forth. Use the following formulas, for the Gregorian calendar: y0 = y - (14 - m)/12 x = y0 + y0/4 - y0/100 + y0/400 m0 = m + 12*((14 - m)/12)- 2 d0 = (d + x + (31*m0)/12) % 7 Please note that all the divisions in the formulas above are integer divisions. They represent the quotient part of the division between the two operands. For example, on what day of the week was August 2, 1953? y = 1953 - 0 = 1953 x = 1953 + 1953/4 - 1953/100 + 1953/400 -= 2426 m = 8 + 12*0 - 2 = 6 d = (2 + 2426 + (31*6)/12) % 7 = 2443 % 7 = 0 (Sunday) Here's an example of a possible sample run: Please enter the month: 8 Please enter the day: 2 Please enter the year: 1953 The day of the week for the given date is: 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
