您的位置:首页 > 其它

第十六周-计算该日在本年中是第几天

2016-12-20 17:02 190 查看
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int year;
int month;
int day;
} y_m_d;
int main()
{
y_m_d date;
int days(y_m_d);
//y_m_d是自定义的类型
int day_sum;
scanf("%d%d%d",&date.year,&date.month,&date.day);
day_sum=days(date);
printf("%d\n",day_sum);
return 0;
}
int days(y_m_d date)
{
int i,count=date.day;
for(i=1; i<date.month; ++i)
{
switch(i)
{
case 2:
count+=((date.year%4==0&&date.year%100!=0)||date.year%400==0)?29:28;
break;
case 4:
case 6:
case 9:
case 11:
count+=30;
break;
default:
count+=31;
break;
}
}
return count;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: