#include <stdio.h>
int main()
{
int year,month,day,i,j=0;
printf("请输入日期");
scanf("%d",&year);
scanf("%d",&month);
scanf("%d",&day);
for(i=1;i<month;i++)
{
switch(i)
{
case 1:j+=31;break;
case 2:j+=28;break;
case 3:j+=31;break;
case 4:j+=30;break;
case 5:j+=31;break;
case 6:j+=30;break;
case 7:j+=31;break;
case 8:j+=31;break;
case 9:j+=30;break;
case 10:j+=31;break;
case 11:j+=30;break;
default:printf("输入有误");break;
}
}
if(year%400==0 || year%100!=0 && year%4==0)
{
if(month<=2) printf("%d年%d月%d日是该年的第%d天",year,month,day,j+day);
else printf("%d年%d月%d日是该年的第%d天",year,month,day,j+day+1);
}
else printf("%d年%d月%d日是该年的第%d天",year,month,day,j+day);
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int year, month, day, i, j = 0;
printf("请输入日期\n");
cin >> year;
cin >> month;
cin >> day;
for (i = 1; i<month; i++)
{
switch (i)
{
case 1:j += 31; break;
case 2:j += 28; break;
case 3:j += 31; break;
case 4:j += 30; break;
case 5:j += 31; break;
case 6:j += 30; break;
case 7:j += 31; break;
case 8:j += 31; break;
case 9:j += 30; break;
case 10:j += 31; break;
case 11:j += 30; break;
default:printf("输入有误"); break;
}
}
if (year % 400 == 0 || year % 100 != 0 && year % 4 == 0)
{
if (month <= 2) printf("%d年%d月%d日是该年的第%d天", year, month, day, j + day);
else printf("%d年%d月%d日是该年的第%d天", year, month, day, j + day + 1);
}
else printf("%d年%d月%d日是该年的第%d天", year, month, day,j + day);
system("pause");
return 0;
}