zoukankan      html  css  js  c++  java
  • 万年历

    #include<stdio.h>
    #include<stdlib.h>
    
    char* month_str[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
    int
    mon_day[][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}};
    
    int IsLeapYear(int year)   /*find out the year is leap year or not*/
    {
        if((year%4==0&&year%100!=0)||(year%400==0))
            return 1;
        else
            return 0;
    }
    
    int DaySearch(int year,int month,int day)/*search what day this day is*/
    {
        int days=0;
        int m,i;
        for(i=1900;i<year;i++)
            if(IsLeapYear(i))days=days+366;
            else days=days+365;
        for(m=1;m<month;m++)
            days=days+mon_day[IsLeapYear(year)][m-1];
        return((int)days%7);
    }
    
    int PrintAllYear(int year)/*print the all year*/
    {
        int temp;
        int i,j;
        printf("
    
                                      %d Calander
    ",year);
        for(i=1;i<=12;i++){
            printf("
    
                          %s
    
    ",month_str[i-1]);
            printf("星期一 星期二 星期三 星期四 星期五 星期六 星期日
    ");
            temp=DaySearch(year,i,1);/*本月的1号是星期几*/
                for(j=1;j<=mon_day[IsLeapYear(year)][i-1]+temp;j++)
                {
                    if(j-temp<=0)     printf("       ");
                    else if(j-temp<10)printf("%d      ",j-temp);
                          else printf("%d      ",j-temp);
                          if(j%7==0)printf("
    ");
                }
        }
        return 0;
    }
    
    
    int main()
    {
        int option=1;
        char ch;
        int year,month,day;
    
        while(1){
            printf("
    请输入你要打印的年份(XXXX)");
            scanf("%d",&year);
            PrintAllYear(year);
            printf("
    还要继续打印吗?(Y/N)
    ");
            scanf("
    %c",&ch);
            if(ch=='N'||ch=='n')break;
        }
        return 0;
    }
  • 相关阅读:
    深入理解加密、解密、数字签名和数字证书
    支付网关的设计
    spring boot Rabbitmq集成,延时消息队列实现
    五一之起一台服务器玩玩-u盘安装centos
    shell初识
    用户身份切换之初窥企业远程用户没root还有root权限
    man帮助文档打印
    开源镜像软件下载网址{转载}
    bash shell第一课
    jQuery常用ajax操作
  • 原文地址:https://www.cnblogs.com/lxhlxx900126/p/3349108.html
Copyright © 2011-2022 走看看