代码如下:
#include<stdio.h>
int main()
{
int total;
int year,leap,day,i,mon;
int m=0;
int mon_1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int mon_2[12]={31,28,31,30,31,30,31,31,30,31,30,31};
printf("Please input year:\n");
scanf("%d",&year);
if(year%4==0)//判断该年是闰年还是平年
if(year%100==0)
if(year%400==0)
leap=1;
else
leap=0;
else
leap=1;
else
leap=0;
printf("Please input month:\n");//求输入在输入月份之前的月份天数总和
scanf("%d",&mon);
if(leap==1)
for(i=1;i<mon;i++)
m+=mon_1[i];
if(leap==0)
for(i=1;i<mon;i++)
m+=mon_2[i];
printf("Please input day:\n");//加上该月已过的天数,得到总和
scanf("%d",&day);
total=day+m;
printf("The date is on the %d day of the year\n",total);
return 0;
}
|