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

    #include <stdio.h>
    
    int year(int y)
    {
        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
            return 366;
        else
            return 365;
    }
    
    int main(int argc, const char * argv[])
    {
        int y;
        
        // 每月多少天
        int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        
        printf("请输入年份:
    ");
        scanf("%d", &y);
        
        int sum = 0;
        for (int i = 1; i < y; i++) {
            sum += year(i);
        }
        
        int week = (sum + 1) % 7; // 1月1日星期几
        
        if (year(y) == 366) {
            days[1] = 29;
        }
        
        printf("
    %d年日历如下:
    ", y);
        for (int i = 0; i < 12; i++) {
            printf("        %d月
    ", i+1);
            printf("  7  1  2  3  4  5  6
    ");
            printf("=====================
    ");
            
            for (int i = 0; i < week; i++) {
                printf("   ");
            }
            
            int begin = 1;
            while (begin <= days[i]) {
                printf(" %02d", begin);
                begin++;
                week = (week + 1) % 7;
                if (week == 0) {
                    printf("
    ");
                }
            }
            printf("
    
    ");
        }
        
        
        return 0;
    }


    运行结果:


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    linux 11201(11203) ASM RAC 安装
    [学习笔记]多项式对数函数
    linux 10201 ASM RAC 安装+升级到10205
    tar
    [学习笔记]多项式开根
    gzip
    小朋友和二叉树
    zip
    bzoj5016 一个简单的询问
    unzip
  • 原文地址:https://www.cnblogs.com/liuqblog/p/4948156.html
Copyright © 2011-2022 走看看