C-language implementation of the 10 thousand small program (with code)

Source: Internet
Author: User
This article mainly introduces the 10 thousand Tib mini-program implemented in C language, which is relatively simple. if you are a friend of C language date computing, you can refer to the next article to introduce the 10 thousand Tib mini-program implemented in C language, relatively simple. For more information about C-language date computing, see

The program simply enters a year (year after 1901), and then the program outputs the calendar of the year 12 months.


# Include
 
  
# Define Mon 1 # define Tues 2 # define Wed 3 # define Thur 4 # define Fri 5 # define Sat 6 # define Sun 0 # define January_days 31 # define February_days 28 # define March_days 31 # define interval 30 # define May_days 31 # define June_days 30 # define interval 31 # define interval 31 # define interval 30 # define October_days 31 # define November_days 30 # define December_days 31 # define first1month # define first2month interval + interval # define first3month interval + March_days # define first4month interval + interval # define first5month interval + March_days + interval + May_days # define first6month interval + week + March_days + week + May_days + June_days # define first7month week + March_days + week + May_days + June_days \ + week # define first8month week + March_days + week + May_days + june_days \ + week # define first9month week + March_days + week + May_days + June_days \ + week # define first10month week + February_days + March_days + week + May_days + june_days \ + quota + October_days # define first11month quota + February_days + March_days + quota + May_days + June_days \ + quota + October_days + quota = 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 "limit L"; 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 a month in the format */void first_line_print (int month, int year) {// printf ("% 20 s % d \ n", month_name (month), year); printf ("% 8d year % s \ n", year, month_name (month);}/* print the name of the week by format */void week_print () {// printf ("%-6 s %-6 s %-6 s %-6 s %-6 s %-6 s %-6 s %-6s \ n", "Sun. "," Mon. "," Tues. "," Wed. "," Thur. "," Fri. "," Sat. "); printf (" %-3 s %-3 s %-3 s %-3 s %-3 s %-3 s %-3 s \ n ", "," 1 "," 2 "," 3 "," 4 "," 5 "," 6 ");} /* calculate the number of days 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
  
   
2) {if (year % 4 = 0) & (year % 100! = 0) | (year % 400 = 0) {leap_year_count ++ ;}} elseif (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 day of the week on the first day of the month */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; retur N weekday;}/* print the day of the month in sequence */void print_in_turn (int month, int firstday, int year) {int I = 1; int weekday; switch (firstday) {case Sun: break; case Mon: printf ("%-3 s", ""); break; case Tues: printf ("%-6 s ",""); break; case Wed: printf ("%-9 s", ""); break; case Thur: printf ("%-12 s", ""); break; case Fri: printf ("%-15 s", ""); break; case Sat: printf ("%-18 s", ""); break ;} switch (month) {case 1: case 3: case 5: case 7: case 8: case 10: case 12: {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/* YEAR */{for (I = 0; I <28; I ++) {weekday = (firstday + I) % 7; printf ("%-3d", I + 1); if (weekday = Sat) {printf ("\ n") ;}} break ;}case 4: case 6: case 9: case 11: {for (I = 0; I <30; I ++) {weekday = (firstday + I) % 7;/* calculate the day of the week */printf ("%-3d", I + 1 ); if (weekday = Sat) {printf ("\ n");/* if it is Saturday, line feed */} break ;}} 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");} void main_calendar (int year) {int I; for (I = 1; I <= 12; I ++) {main_month (I, year) ;}} int main () {int year; printf ("Enter the year: year ="); scanf ("% d", & year); printf ("\ n"); while (year <1902) {printf ("Enter year \ n greater than 1901"); printf ("Enter year: year ="); scanf ("% d", & year ); printf ("\ n");} main_calendar (year); scanf (""); return 0 ;}
  
 

Run:

The above is the details of the 10 thousand small applet (with code) implemented in C language. For more information, see other related articles in the first PHP community!

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.