How to print the calendar of a certain month in a certain year in C language
This article mainly introduces "how to print the calendar of a certain month in a certain year in C language". In the daily operation, I believe that many people have doubts about how to print the calendar of a certain month in a certain year in C language. The editor consulted all kinds of data and sorted out a simple and easy-to-use operation method. I hope it will be helpful for you to answer the doubt of "how to print a calendar of a month in a certain year in C language". Next, please follow the editor to study!
General ideas:
① determines whether the year entered is a leap year.
② calculates that the first day of the input month is the day of the year.
③ calculates what day the first day of the input month is.
④ output.
Use in combination with code: # define _ CRT_SECURE_NO_WARNINGS 1#include int main () {int arr1 [] = {0pence 31je 28je 31je 30je 31je 31pr 31pr 31pr 31}; int I = 0; int year = 0; int month = 0; int days = 0; int week = 0 year / scanf ("% d% d", & year, & month) If ((year% 4 = = 0 & & year% 100! = 0) | | (year% 400 = = 0) / / determine whether it is a leap year {arr1 [2] = 29 days++ / 29 days of February in a leap year} for (I = 0; I < month; +) {days+ = arr1 [I]; / calculate the number of days of the year} days++ / / the first day of the month should also be counted in / / apply the formula for calculating the day of the week week = (year-1 + (year-1) / 4-(year-1) / 100 + (year-1) / 400 + days)% 7; printf ("Day one, two, three, four, five\ n"); / / header int arr2 [50] = {0}; for (I = 0) I < week; iTunes +) {printf (""); / / the integer array cannot store spaces, so print the spaces directly} arr2 [week] = 1; for (I = week + 1; I