万年历分析

Posted 旭日初扬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了万年历分析相关的知识,希望对你有一定的参考价值。

一、输入年份,判断这一年时闰年还是平年

#include "stdio.h"

#include "public.h"

#define BASE 2000
/*
要求:输入年份出这一年的日历
参考:2000  1月1日  星期日
*/

//  结构体初始化
void DataStructInit(void)

    date.year = 0;
    date.month = 0;
    date.month_day=0;
    date.week = 0;
    date.day = 0;



void main(void)

    /*
    char weeks1  = "sun"            &weeks=100(weeks1内存)    sun存在内存100处
    char *weeks2(一级指针)         *weeks2 = &weeks1          weeks2存在内存150处,weeks2 指向内存100处
    char **weeks3(二级指针)        
    */
    //  用于保存星期几
    char **weeks[] = "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT";

    //  平年于闰年
    unsigned int Year_Leap[2][12] = 
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  平年
        31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  闰年
    ;

  

    DataStructInit();

    printf("Please enter the year:\\n");
    scanf("%d", &date.year);

     if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0)
    
        leap = TRUE; //  瑞年
        date.day = 366;
        printf("这一年时闰年共有:%d天\\n",date.day);
    
    else
    
        leap = FALSE;
        date.day = 365;
        printf("这一年是平年共有:%d天\\n",date.day);
    
    
    
    

typedef struct

    unsigned int year;
    unsigned int month;
    unsigned int month_day;
    unsigned int week;
    unsigned int day;
 DATE;

DATE date;

//  判断  平年 or 闰年
    unsigned int leap;

typedef enum LEAP_NON

    FALSE = 0,
    TRUE = !FALSE
;

二、输出闰年  or  平年及对应月份的天数

#include "stdio.h"

#include "public.h"

#define BASE 2000
/*
要求:输入年份出这一年的日历
参考:2000  1月1日  星期日
*/

//  结构体初始化
void DataStructInit(void)

    date.year = 0;
    date.month = 0;
    date.month_day=0;
    date.week = 0;
    date.day = 0;



void main(void)

    /*
    char weeks1  = "sun"            &weeks=100(weeks1内存)    sun存在内存100处
    char *weeks2(一级指针)         *weeks2 = &weeks1          weeks2存在内存150处,weeks2 指向内存100处
    char **weeks3(二级指针)        
    */
    //  用于保存星期几
    char **weeks[] = "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT";

    //  平年于闰年
    unsigned int Year_Leap[2][12] = 
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  平年
        31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  闰年
    ;

  

    DataStructInit();

    printf("Please enter the year:\\n");
    scanf("%d", &date.year);

     if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0)
    
        leap = TRUE; //  瑞年
        date.day = 366;
        printf("这一年时闰年共有:%d天\\n",date.day);
    
    else
    
        leap = FALSE;
        date.day = 365;
        printf("这一年是平年共有:%d天\\n",date.day);
    
    
    //   12个月
    for(;date.month<12;date.month++)
        
        
        //  每个月的天数
        for(date.month_day=0;date.month_day<Year_Leap[leap][date.month];date.month_day++)
        
        printf(" %d ",date.month_day+1);
       
        
         printf("\\n");
    
    
    
    

终结

#include "stdio.h"

#include "public.h"

#define BASE 2000
/*
要求:输入年份出这一年的日历
参考:2000  1月1日  星期日
*/

//  结构体初始化
void DataStructInit(void)

    date.year = 0;
    date.month = 0;
    date.month_day=0;
    date.week = 0;
    date.week_day=0;
    date.day = 0;



void main(void)

    /*
    char weeks1  = "sun"            &weeks=100(weeks1内存)    sun存在内存100处
    char *weeks2(一级指针)         *weeks2 = &weeks1          weeks2存在内存150处,weeks2 指向内存100处
    char **weeks3(二级指针)        
    */
    //  用于保存星期几
    char **weeks[] =  "MON", "TUE", "WED", "THU", "FRI","SAT", "SUN";

    //  平年于闰年
    unsigned int Year_Leap[2][12] = 
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  平年
        31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, //  闰年
    ;

    char **month_big[]="一","二","三","四","五","六","七","八","九","十","十一","十二";
    // 一个中文占4个字节
    // char num[12][8]="壹","贰","叁","肆","伍","陆","柒","捌","玖","拾","拾壹","拾贰";
  

    // 月份输出 month_put
    unsigned int month_put=0;
   

    DataStructInit();

    printf("Please enter the year:\\n");
    scanf("%d", &date.year);

     if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0)
    
        leap = TRUE; //  瑞年
        date.day = 366;
        printf("这一年时闰年共有:%d天\\n",date.day);
    
    else
    
        leap = FALSE;
        date.day = 365;
        printf("这一年是平年共有:%d天\\n",date.day);
    

   
    
    //   12个月
    for(;date.month<12;date.month++)
        
        
       //  每个月的天数
        printf("\\n---------------- %d月:----------------\\n",date.month+1);
        
        date.week = date.day %7;
         if(date.week==0)
         
            date.week=7;
         else
             date.week +=1;
         

         printf("\\n");

         for(date.week_day=0;date.week_day<7;date.week_day++)
         
             printf("%s \\t",weeks[date.week_day]);
         

               
         for(date.week_day=1;date.week_day<date.week;date.week_day++)
         
             printf("\\n");
         

        for(date.month_day=0;date.month_day<Year_Leap[leap][date.month];date.month_day++)
        
              printf(" %d \\t",date.month_day+1);
            if(date.month_day%7==(7-date.week+1))
            
                printf("\\n");
            
         
           
        

         printf("\\n");
        date.day += Year_Leap[leap][date.month];
    
    

以上是关于万年历分析的主要内容,如果未能解决你的问题,请参考以下文章

万年历分析

基于FPGA的电子万年历设计

年份月数天数

百万年薪python之路 -- 第二周 --模拟博客园系统

Openfire分析之一:Openfire与XMPP协议

万年历 编程