Question: Compose a program dayOfWeek program that accepts a date as input and writes the day of the week on which that date falls. Your program

Compose a program dayOfWeek program 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. Note: You can assume that the user is entering a valid date.

Use the following formulas, for the 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

All the divisions in the formulas above are integer divisions. 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)

Heres 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!