您的位置:首页 > 编程语言 > C语言/C++

C语言编程练习(day of the year)

2010-11-28 01:38 302 查看
#include<stdio.h>

int sum_day(int month, int day); /*求得总天数,为考虑闰年*/

int leap(int year); /*是否闰年*/

int main(void)

{

int year, month, day;

int days;

printf("Please input the date(year,month,day): ");

scanf("%d,%d,%d", &year, &month, &day);

days = sum_day(month, day);

if(leap(year) && month >=3)

{

days = days + 1;

printf("This is leap year!\n");

}

else

{

printf("This is not leap year.\n");

}

printf("This is the %dth day of the year.\n", days);

return 0;

}

static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int sum_day(int month, int day)

{

int i;

for(i=1; i<month; i++)

{

day = day + day_tab[i];

}

return day;

}

int leap(int year)

{

int lp;

lp = (year % 4 == 0 && year %100 != 0) || (year % 400 == 0);

return lp;

}
本文出自 “奋斗成就卓越” 博客,请务必保留此出处http://tiger506.blog.51cto.com/318536/434557
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: