-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork process
17 lines (17 loc) · 2.32 KB
/
work process
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Step 1. The program begins by including the standard input/output library in C using the `#include <stdio.h>` directive.
Step 2. The `main()` function is defined, which is the entry point of the program.
Step 3. Inside the `main()` function, several variables are declared, including `month`, `year`, `daysInMonth`, `startingDay`, and `dayOfWeek`.
Step 4. The user is prompted to enter the month and year for which they would like to print a calendar using the `printf()` and `scanf()` functions.
Step 5. A switch statement is used to determine the number of days in the given month based on its value. If the month is February (i.e., `month` equals 2),
the program checks if the year is a leap year to determine if the month has 29 or 28 days.
Step 6. The starting day of the month is calculated using a formula that takes into account the number of days in previous years, accounting for leap years, and adding the number of days in previous months in the current year.
The resulting value is stored in the `startingDay` variable.
Step 7. The day of the week that the first day of the month falls on is calculated by taking the modulus of `startingDay` divided by 7. This is stored in the `dayOfWeek` variable.
Step 8. The header for the calendar grid is printed using the `printf()` function to display the abbreviated names of the days of the week.
Step 9. A `for` loop is used to print out spaces to align the first day of the month with the correct day of the week, using the value of `dayOfWeek`.
Step 10. Another `for` loop is used to print out the days of the month, using the `printf()` function and the `-5d` format specifier to align the numbers in the calendar grid.
The program checks if the last day of the week (Saturday) has been printed by incrementing the value of `dayOfWeek` and checking if it is greater than 6. If it is,
a newline character is printed to start a new row in the calendar grid.
Step 11. Once all of the days in the month have been printed, the program checks if the last row of the calendar grid is incomplete (i.e., if the last day of the month does not fall on a Saturday).
If it is, another newline character is printed to end the calendar grid.
Step 12. The program ends with the `return 0;` statement in the `main()` function, indicating that the program has completed successfully.