计算某一天是一年的第几天

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

int main()

{ struct date

{ int day;

int month;

int year;

}days;

int leap,sum=0,k=0;

printf("请输入年,月,日(中间用空格分开):");

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

if((days.year%4==0&&days.year%100!=0)||days.year%400==0) leap=1;

if(((days.month==1||days.month==3||days.month==5||days.month==7||days.month==8||days. month==110||days.month==12)&&days.day>31)||((days.month==4||days.month==6||days.mo nth==9||days.month==11)&&days.day>30))

printf("输入天数错误.\n");

if(days.month==2&&days.day>29)

printf("输入天数错误.\n");

if(days.month==2&&leap!=1&&days.day>28)

printf("输入天数错误.\n");

else

{switch(days.month)

{case 1:sum=days.day;break;

case 2:sum=31+days.day;break;

case 3:sum=59+days.day;break;

case 4:sum=90+days.day;break;

case 5:sum=120+days.day;break;

case 6:sum=151+days.day;break;

case 7:sum=181+days.day;break;

case 8:sum=212+days.day;break;

case 9:sum=243+days.day;break;

case 10:sum=273+days.day;break;

case 11:sum=304+days.day;break;

case 12:sum=334+days.day;break;

default:{k=1;printf("输入月份错误.\n");}

}

if(days.month>=3&&((days.year%4==0&&days.year%100!=0)||days.year%400==0)) ++sum;

if(sum!=0&&k!=1)

printf("这是%d年的第%d天\n.",days.year,sum);}

return 0;

}

相关文档
最新文档