zoukankan      html  css  js  c++  java
  • 编程基本功——判断某天是一年中的第几天

    一、分析

    (1)首先分析是否为闰年,若为闰年则2月为29天

    (2)其次计算之前的几个月一共有多少天

    (3)最终加上该天在月中是多少天

    二、源码

       1: #include <stdio.h>
       2:  
       3: int Day(int year, int month, int date)
       4: {
       5:     int months[13] = {0, 31, 0, 31, 30,
       6:                       31, 30, 31, 31, 30,
       7:                       31, 30, 31};
       8:     int i, days = 0;
       9:  
      10:     if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
      11:         months[2] = 29;
      12:     else
      13:         months[2] = 28;
      14:  
      15:     for (i = 1; i < month; ++i)
      16:     {
      17:         days += months[i];
      18:     }
      19:     days += date;
      20:     return days;
      21: }
      22:  
      23: int main()
      24: {
      25:     printf("the days of 25th May 2010 is %d\n", Day(2010, 5, 25));
      26:     return 0;
      27: }
  • 相关阅读:
    CSS属性值一览
    CSS属性一览
    CSS选择器一览
    HTML颜色编码
    游戏
    数据库系统概念
    关于总结
    章节测试
    我的博客皮肤
    Emeditor所有快捷键操作
  • 原文地址:https://www.cnblogs.com/steven_oyj/p/1743263.html
Copyright © 2011-2022 走看看