zoukankan      html  css  js  c++  java
  • c语言 简单的天数计算器

    #include<stdio.h>
    #include<stdbool.h>
    #include<stdlib.h>
    int count_days(int month,bool leap)
    {
        switch(month)
        {
            case 1:case 3:case 5:case 7:case 8:case 10:case 12:month=31;break;
            case 2:
                if(leap)
                    month=28;
                else
                    month=29;
                break;
            default:month=30;
        }
        return month;
    }
    bool is_leap(int year)
    {
        if((year%4==0&&year%100!=0)||year%400==0)
            return true;
        else
            return false;
    }
    int sum(int month,int day,bool leap){
        int Days=0;
        for(int i=1;i<month;i++)
            Days+=count_days(i, leap);
        Days+=day;
        return Days;
    }
    int main(){
        int year;
        int month;
        int day;
        printf("一次输入年月日,分别以空格隔开
    ");
        scanf("%d%d%d",&year,&month,&day);
        bool leap=is_leap(year);
        int Mon_day=count_days(month, leap);
        if(day>Mon_day){
            printf("error
    ");
            exit(0);
        }
        int count=sum(month, day, leap);
        printf("今年已经过了%d天
    ",count);
    }
  • 相关阅读:
    #4702. gcd
    独特的树叶

    搞笑的代码 ( funny )
    越野赛车问题
    删边(cip)
    最长公共子序列
    美食节
    线段树
    新年快乐
  • 原文地址:https://www.cnblogs.com/oldfish123/p/13646504.html
Copyright © 2011-2022 走看看