[C Language exercises] Perpetual calendar enhanced Edition

Source: Internet
Author: User

/*** @ Copyright 2011 Chunhui Wang *** wangchunhui@wangchunhui.cn */# include <stdio. h> int main () {printf ("\ t Perpetual calendar \ n "); printf ("\ t ------ Made by Chunhui Wang \ n"); int I, year, month; int day; // record the day of the week on the first day of each month. Int date; // Changes in the week of each year. Values of the year plus 1 and the LEAP plus 2 are calculated. Int a [13] = {, 28, 31, 30, 31, 30, 31, 30, 31}; // number of days of the month. Int Year [10000]; // the number of weeks on the first day of each Year. Year [1900] = 1; for (I = 1900; I <9999; I ++) {date = 1; if (I % 4 = 0) & (I % 100! = 0) | (I % 400 = 0) {date = 2;} Year [I + 1] = (Year [I] + date) % 7 ;} while (1) {printf ("Enter the year (for example, 1900):"); scanf ("% d", & year); printf ("Enter the month (for example, 01): "); scanf (" % d ", & month); a [2] = 28; if (year % 4 = 0) & (year % 100! = 0) | (year % 400 = 0) & (month> = 2) {a [2] = 29;} day = Year [year]; for (I = 1; I <month; I ++) {day = day + a [I];} day = day % 7; printf ("\ t % d month \ n", year, month ); printf ("\ t Monday \ t Tuesday \ t Wednesday \ t Friday \ t Saturday \ n"); for (I = 0; I <day; I ++) {printf ("\ t");} if (day = 0) printf ("\ t"); for (I = 0; I <a [month]; I ++) {printf ("% d \ t", I + 1); if (I + day) % 7 = 0) {printf ("\ n \ t") ;}} printf ("\ n") ;}return 0 ;}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.