C language implementation of a million calendar applet _c language

Source: Internet
Author: User

The program simply enters a year (years after 1901), and then the program prints the calendar for the year 12 months.

#include <stdio.h> #define MON 1 #define Tues 2 #define WED 3 #define THUR 4 #define FRI 5 #define SAT 6 #define SUN 0 #define JANUARY_DAYS #define FEBRUARY_DAYS #define MARCH_DAYS #define April_days #d  Efine may_days #define JUNE_DAYS #define JULY_DAYS #define AUGUST_DAYS #define #define OCTOBER_DAYS #define NOVEMBER_DAYS #define DECEMBER_DAYS #define First1month january_days #defi NE first2month january_days+february_days #define FIRST3MONTH january_days+february_days+march_days #define First4month january_days+february_days+march_days+april_days #define First5month January_days+february_days+march_ Days+april_days+may_days #define First6month January_days+february_days+march_days+april_days+may_days+june_days # Define First7month january_days+february_days+march_days+april_days+may_days+june_days \ +July_days #define Firs T8month January_days+february_days+march_days+april_daYs+may_days+june_days \ +july_days+august_days #define First9month january_days+february_days+march_days+april_d Ays+may_days+june_days \ +july_days+august_days+september_days #define First10month january_days+february_days+m Arch_days+april_days+may_days+june_days \ +july_days+august_days+september_days+october_days #define First11mont H january_days+february_days+march_days+april_days+may_days+june_days \ +july_days+august_days+september_days+oc
tober_days+november_days int known_weekday = Tues;
int known_year = 1901;
int konwn_month = 1;

int known_day = 1;
		int day_count (int month) {switch (month) {case 1:return 0;break;
		Case 2:return First1month;break;
		Case 3:return First2month;break;
		Case 4:return First3month;break;
		Case 5:return First4month;break;
		Case 6:return First5month;break;
		Case 7:return First6month;break;
		Case 8:return First7month;break;
		Case 9:return First8month;break; Case 10:return First9month;break;
		Case 11:return First10month;break;
	Case 12:return First11month;break;
			}/*char * Month_name (int month) {switch (month) {case 1:return ' January ';
		Break
			Case 2:return "February";
		Break
			Case 3:return "March";
		Break
			Case 4:return "April";
		Break
			Case 5:return "may";
		Break
			Case 6:return "June";
		Break
			Case 7:return "July";
		Break
			Case 8:return "August";
		Break
			Case 9:return "September";
		Break
			Case 10:return "October";
		Break
			Case 11:return "November";
		Break
			Case 12:return "December";
		Break
	Default:break;
			}}*/char * month_name (int month) {switch (month) {case 1:return "January";
		Break
			Case 2:return "February";
		Break
			Case 3:return "March";
		Break
			Case 4:return "April";
		Break
			Case 5:return "May";
		Break
			Case 6:return "June";
		Break
			Case 7:return "July";
		Break
			Case 8:return "August";
		Break Case 9:rEturn "September";
		Break
			Case 10:return "October";
		Break
			Case 11:return "November";
		Break
			Case 12:return "December";
		Break
	Default:break;
	}//* Print the name of the month in the format/void first_line_print (int month, int year) {//printf ("%20s%d \ n", Month_name (month), year);
printf ("%8d%s \ n", year, Month_name (month));  */* Print week name in format/void Week_print () {//printf ("%-6s%-6s%-6s%-6s%-6s%-6s%-6s\n", "Sun.", "Mon.", "Tues.", "Wed.", "Thur.",
	"Fri.", "Sat.");
printf ("%-3s%-3s%-3s%-3s%-3s%-3s%-3s\n", "Day", "one", "two", "three", "four", "five", "six");
	}/* Calculates the distance between the month and the known day of the year/int date_distance_count (int month, int year) {int leap_year_count = 0;
	int i;

	int distance; if (Year > Known_year) {for (i=known_year i<year; i++) {if ((i%4 = 0) && (i%100!= 0)) | |
			(i%400 = 0))		
			{leap_year_count++; } if (Month > 2) {if ((year%4 = = 0) && (year%100!= 0) | |
			(year%400 = 0))		
			{leap_year_count++;
}} else if (year = = Known_year) {		if (Month > 2) {leap_year_count = 1;

	} distance = (year-known_year) *365 + Leap_year_count + day_count (month);	
return distance;
	/* Determine the first day of the month is the Week/int makesure_firstday_weekday (int month, int year) {int date_distance = 0;

	int weekday;
	Date_distance = Date_distance_count (month, year);

	Weekday = (Known_weekday + date_distance)%7;	
return weekday;
	}//* Print out the day of the Month/void Print_in_turn (int month, int firstday, int year) {int i = 1;

	int weekday;
		Switch (firstday) {case sun:break;
			Case mon:printf ("%-3s", "");
		Break
			Case tues:printf ("%-6s", "");
		Break
			Case wed:printf ("%-9s", "");
		Break
			Case thur:printf ("%-12s", "");
		Break
			Case fri:printf ("%-15s", "");
		Break
			Case sat:printf ("%-18s", "");
	Break 
			Switch (month) {case 1:case 3:case 5:case 7:case 8:case 10:case-for (i=0; i<31; i++)
				{weekday = (FirstDay + i)%7;
				
				printf ("%-3d", i+1); if (weekday == Sat) {printf ("\ n");
		}} break; Case 2: {if ((year%4 = 0) && (year%100!= 0) | | (year%400 = 0))
					/* Leap Year * * for (i=0 i<29; i++) {weekday = (FirstDay + i)%7;
					
					printf ("%-3d", i+1);
					if (weekday = Sat) {printf ("\ n");
			}} break;
					else/* excepting/{for (i=0 i<28; i++) {weekday = (FirstDay + i)%7;
					
					printf ("%-3d", i+1);
					if (weekday = Sat) {printf ("\ n");
			}} break; 4:case 6:case 9:case: {for (i=0; i<30; i++) {weekday = (FirstDay + i)%7;/* calculate the day
				
				Is the day of the week */printf ("%-3d", i+1);
		if (weekday = Sat) {printf ("\ n");/* If it is Saturday, then break the line */}};

	}} void Date_print (int month, int year) {int firstday;
	FirstDay = Makesure_firstday_weekday (month, year);
	Print_in_turn (month, FirstDay, year);
printf ("\ n");
} void Main_month (int month, int year){first_line_print (month, year);
	Week_print ();
	Date_print (month, year);
printf ("\ n \ nthe");
	} void Main_calendar (int year) {int i;
	For (i=1. i<=12; i++) {main_month (I, year);

	int main () {int year;
	printf ("Please enter year: years =");
	scanf ("%d", &year);

	printf ("\ n");

		while (year < 1902) {printf ("Please enter an age greater than 1901 \ n");
		printf ("Please enter year: years =");
		scanf ("%d", &year);
	printf ("\ n");
	
	} Main_calendar (year);
	scanf ("");
return 0; }

Run Effect chart:

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.