In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to print out the calendar of a certain year in C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "C language how to print out a calendar for a certain year"!
Enter a year (after 1970) and print the calendar for that year in 2 / 6 format.
Main idea: traverse the date, mark what each line should print according to the date, store it in an array, and then traverse the array and print it line by line according to the contents of the array. The code is as follows:
/ print calendar # define _ CRT_SECURE_NO_WARNINGS#include char month [12] [10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; / / calculate the date of the year int day_in_year (int y, int m, int d) {int r_day = 0 Int m_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 31, 30, 31}; / / the number of days per month m_days [1] + = y% 400 = = 0 | y% 4 = = 0 & y% 100! = 0; for (int I = 0; I < m-1; + + I) {r_day + = m _ days [I];} r_day + = d; } / / calculate the day of the week int getWeek (int y, int m, int d) {/ / first calculate the number of days from Thursday, January 1st, 1970, int days = 0; / / the day of the day int res; / / the day of the week if (y = 1970) {days = day_in_year (y, m, d);} else {for (int I = 1970; I < y) + + I) {days = days + 365 + (I% 400 = = 0 | I% 4 = = 0 & & I% 100! = 0);} days + = (day_in_year (y, m, d)-1); / / because the distance is calculated in how many days, you need to subtract one} / / then calculate the day of the week res = (days + 4)% 7; return res } / / print calendar void displayCalendar (int y) {int m_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31}; / / number of days per month m_days [1] = 28 + (y% 400 = = 0 | y% 4 = = 0 & y% 100! = 0); the first day of the month on the left of int week_l;// is the day of the week for on the right side of the month (int m = 0) M < 6; + + m) {/ m controls the month, which is 1 / / smaller than the actual month. The header of the printed calendar printf ("%-12s%-12s\ n", month [m], month [m + 6]) Printf ("-\ n"); printf ("Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat\ n"); week_l = getWeek (y, m + 1,1) / find out what day the first day of the month on the left is week_r = getWeek (y, m + 7,1); / / find out what day the first day of the month on the right is int date_l = 1; int date_r = 1; while (date_l
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.