#include
typedef struct
{
int year;
int month;
int day;
}date;
int days(date d)
{
int num = 0;
int m, da, i;
if ((d.year %4 == 0 && d.year %100!=0)||(d.year % 400 == 0))
{
for (m = 1; m <= d.month ; m++)
{
if (m == 2)
da = 29;
else if (m==4||m==6||m==8||m==11)
da = 30;
else
da = 31;
for (i = 1; i <= da;i++)
{
num++;
if ( m == d.month && i == d.day )
return num;
}
}
}
else
{
for (m = 1; m <= d.month ; m++)
{
if (m == 2)
da = 28;
else if (m==4||m==6||m==8||m==11)
da = 30;
else
da = 31;
for (i = 1; i <= da;i++)
{
num++;
if ( m == d.month && i == d.day )
return num;
}
}
}
}
int main()
{
date d;
scanf("%d%d%d",&d.year,&d.month,&d.day);
printf("%d年%d月%d日 is the %d days of this year",d.year,d.month,d.day,days(d));
return 0;
}
//示例:输入2010 2 5
//输团数搏出塌祥为:2010年2月5日 is the 36 days of this year
//毕袜
#include
using namespace std;
struct Date
{
int year;
int month;
int day;
};
bool run(int);
int days(Date &);
int main()
{
cout<<"请输入你要计改指算的日期:\n";
Date date;
cout<<"年:";
cin>>date.year;
cout<<"月:";
cin>>date.month;
cout<大野<"日:";
cin>>date.day;
cout<
system("pause");
return 0;
}
bool run(int ra)
{
if(ra%4==0&&ra%100!=0||ra%400==0)
return 1;
else
return 0;
}
int days(Date & date)
{
int yue[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int x,sum=0;
for(x=1;x
if(run(date.year)&&date.month>=3)
sum++;
return sum+date.day;
}
#include
struct date
{
int year;
int month;
int day;
};
int leap_year(int a);
int cal_day(struct date a);
/*判断闰年*/
int leap_year(int a)
{
if(a%400==0||(a%4==0&&a%100!=0))
return 1;
else
return 0;
// if(a%400==0)
/前凯饥/慧返 return 1;
// else if(a%100==0)
// return 0;
// else if(a%4==0)
// return 1;
// else
// return 0;
}
/*计算一年中的第几天*/
int cal_day(struct date a)
{
int sum=0,b[]={31,28,31,30,31,30,31,31,30,31,30,31} ;
for(int i=0;i
if(a.month>2)
sum=sum+a.day+leap_year(a.year);
else
sum=sum+a.day;
return sum;
}
void main()
{
struct date a;
int n;
printf("\n请输入日期(年 月 日)\n");
scanf("%d%d%d",&a.year,&a.month,&a.day);
n=cal_day(a);
printf("该日在本年中是第%d天\孙颤n",n);
}