[Classic algorithm]: use C language to draw calendars

Source: Internet
Author: User

[Classic algorithm]: use C language to draw calendars

This blog is intended to write a job and requires a calendar table. So I wrote this program to complete this job.

Functions:
1. query the day of the week.
2. Give the year and month, and draw the calendar of the month.

That is, the above two functions

It is worth mentioning that my code implements the above two functions, but it is not optimal, because I used this program reconstructed with my last code. That's why everyone just needs to take the help. It's really hard to understand it, because I'm too lazy to change it...

Okay, give the code

# Include
  
   
# Include
   
    
Using namespace std; int num1 [12] = {31,29, 31,30, 31,30, 31,31, 30,31, 30,31}; int num2 [12] = {31,28, 31,30, 31,30, 31,31, 30,31, 30,31}; int frontday (int year, int month, int day) {// calculate the number of days after the year int sum = 0; if (year % 100! = 0 & year % 4 = 0) | year % 400 = 0) {for (int I = 0; I
    
     
1) {sum = num1 [month1-1]-day1 + day2; for (int I = month1 + 1; I <= month2-1; I ++) {sum + = num1 [I-1];} return sum ;}} else {if (month1 = mon2) return day2-day1; if (month2-month1) = 1) {return num2 [month1-1]-day1 + day2;} if (month2-month1)> 1) {sum = num2 [month1-1]-day1 + day2; for (int I = month1 + 1; I <= month2-1; I ++) {sum + = num2 [I-1];} return sum ;}} int weekday (int year1, int year2, int month1, int mon2, int day1, int day2) {int sum = 0; // The following classification discusses calculating days between different years if (year2-year1) <0) cout <"small year should be input first, input error"; if (year2-year1) = 0) {sum = JudgeMonthDay (year1, month1, mon22. day1, day2);} if (year2-year1) = 1) sum = backday (year1, month1, day1) + frontday (year2, mon2, day2); if (year2-year1)> 1) {sum = backday (year1, month1, day1) + frontday (year2, mon2, day2); for (int I = year1 + 1; I <= year2-1; I ++) {sum + = isyear (I) ;}} int temp; if (sum + 1) % 7 = 0) temp = 7; else temp = (sum + 1) % 7; return temp;} void main () {int k; cout <"Enter 1 to enter the query function and query the information of a certain day" <
     
      
> K; if (k = 1) {cout <"Enter the date (year, month, and day) You want to search for, separated by spaces." <
      
        > Year2> mon2>> day2; cout <"the date you query is the day of the week" <
       
         > Year2> mon2; int pos; if (year2% 4 = 0 & year2 % 100! = 0) | year2 % 400 = 0) {pos = num1 [month2-1];} else {pos = num2 [month2-1];} cout <
        
       
      
     
    
   
  

Usage:

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.