zoukankan      html  css  js  c++  java
  • 小程序_日期

    /****************************************************************
    题目:输入某年某月某日,判断这一天是这一年的第几天?
    1.程序分析:以3月5日为例,应该先把前两个月的加起来,
    然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时
    需考虑多加一天。
    判断润年year%4==0&&year%100!=0||year%400==0
    *****************************************************************/

    #include <stdio.h>

    void main(void)
    {
    int year = 0;
    int month = 0;
    int day = 0;
    int leap = 0;
    int num = 0;


    while(1)
    {
    printf("Please input year, month, day ! ");
    scanf("%d,%d,%d",&year,&month,&day);

    leap = 0;
    num = 0;
    if((0==year%4)&&(0 != year%100)||(0 == year%400))
    {
    leap = 1;
    }


    switch(month)
    {
    case 12:
    num = num+30;
    case 11:
    num = num+31;
    case 10:
    num = num+30;
    case 9:
    num = num+31;
    case 8:
    num = num+31;
    case 7:
    num = num+30;
    case 6:
    num = num+31;
    case 5:
    num = num+30;
    case 4:
    num = num+31;
    case 3:
    num = num+28+leap;
    case 2:
    num = num+31;
    case 1:
    num = day+num;
    printf("It is %d day of the year ",num);
    break;
    default:
    printf("Pls check invaild month!");
    break;
    }
    fflush(stdin);

    }

    }

    /***************** 今天为了更好的明天 ******************/
  • 相关阅读:
    python学习之调试:
    python学习之调试 错误捕捉及处理
    python之面向对象
    python学习之模块:
    python学习之内部函数:
    python学习之高级特性:
    python学习之结构语句
    python学习之列表元组,字典
    getopt使用例子
    找到系统盘被打满文件
  • 原文地址:https://www.cnblogs.com/cheng-amy/p/5805740.html
Copyright © 2011-2022 走看看