Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need a solution that uses selection without arrays or loops and has only function calls and variable declaration in the main function. C language
I need a solution that uses selection without arrays or loops and has only function calls and variable declaration in the main function. C language
Problem: Given as input the year, day of the week number (0 [Sunday] through 6 [Saturday]), and occurrence number, determine the corresponding date. On page 300 of your C programming text there are several useful formulas given as part of problem 60. All input will be integer data and your program will only be tested with years from 1800 to 2100. Example Execution #1: Enter year number -> 2021 Enter day of week number -> 1 Enter occurrence number -> 11 Desired occurrence #11 of Monday in 2021: March 15 Example Execution #2: Enter year number -> 2020 Enter day of week number -> 6 Enter occurrence number -> 9 Desired occurrence #9 of Saturday in 2020: February 29 Example Execution #3: Enter year number -> 2021 Enter day of week number -> 5 Enter occurrence number -> 1 Desired occurrence #1 of Friday in 2021: January 1 ((year 1)365+ [year -]- year - 17 [year - 1 + 100 400 -- % 7 The formula determines the day based on the values as shown below. Day 0: Sunday Day 1: Monday Day 2: Tuesday Day 3: Wednesday Day 4: Thursday Day 5: Friday Day 6: Saturday Once you know the day for December 31, you simply calculate the days in the year before the month in question. Use a switch statement to make this calculation. (Hint: Use case 12 first, and then fall into case 11, 10... 2.) If the desired month is 12, add the number of days for November (30). If it is 11, add the number of days for October (31). If it is 3, add the number of days for February (28). If it is 2, add the number of days for January (31). If you do not use a break between the months, the switch will add the days in each month before the current month. To this figure, add the day in the current month and then add the result to the day code for December 31. This number modulo seven is the day of the week. There is one more refinement. If the current year is a leap year, and if the desired date is after February, you need to add 1 to the day code. The following formula can be used to determine if the year is a leap year. (!(year % 4) && (year % 100)) || ! (year % 400)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started