#include <stdio.h>
int main(){
int arr[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
printf("请输入要查询的年月日:(格式:2016-6-9)\n");
int year,month,day;
int dayOfYear=0;
scanf("%d-%d-%d",&year,&month,&day);
//判断是否是闰年
if((year%4 ==0 && year%100 !=0) || year%400 == 0){
arr[1] = 29;
}
for (int i = 0 ; i < month-1; i++) {
dayOfYear += arr[i];
}
dayOfYear += day;
printf("%d年%d月%d日是一年中的第%d天\n",year,month,day,dayOfYear);
return 0;
} |