Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207446
  • 博文数量: 127
  • 博客积分: 1998
  • 博客等级: 上尉
  • 技术积分: 1432
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-07 16:41
文章分类

全部博文(127)

文章存档

2014年(41)

2013年(1)

2012年(85)

分类: C/C++

2012-01-11 21:13:19

  1. #include <stdio.h>
  2. #include <stdbool.h>

  3. int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  4. bool is_leap_year(int year)
  5. {
  6.     if((year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0))
  7.         return true;
  8.     else
  9.         return false;
  10. }
  11. int main(int argc, char *argv[])
  12. {
  13.     int i;
  14.     int year, month, day;
  15.     int total = 0;
  16.     printf("Please input a date:");
  17.     scanf("%d%d%d", &year, &month, &day);
  18.     for(i = 1; i < month; i++)
  19.         total += days[i];
  20.     total += day;
  21.     if(is_leap_year(year) && month > 2)
  22.             total ++;
  23.     printf("The %dth day of the year %d.\n",total,year);
  24.     return 0;
  25. }
阅读(785) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~