用c语言编写:给出年、月、日,计算该日是该年的第几天。

2024-11-08 12:35:44
推荐回答(3个)
回答1:

#include
int main()
{
int n,y,r,t,i;
int a[12];
a[1]=31; a[2]=28; a[3]=31;
a[4]=30; a[5]=31; a[6]=30;
a[7]=31; a[8]=31; a[9]=30;
a[10]=31;a[11]=30;a[12]=31;
while (scanf("%d %d %d",&n,&y,&r)!=EOF)
{
t=0;
if((n%4==0 && n%100!=0)||(n%400==0)) a[2]=29; else a[2]=28;
for (i=1;i t+=a[i];
t+=r;
printf("%d\n",t);
}
}

回答2:

#include
struct
{
int year;
int month;
int day;
}date;
void main()
{
int i,days=0;
int day_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("input year,mont,day:\n');
scanf("%d,%d,%d",&date.year,&date.month,&date.day);
for(i=0;idays=days+day_month[i];
days=days+date.day;
printf("%d年%d月%d日是该年的第%d天",date.year,date.month,date.day,days);
}

回答3:

#include
int IsLeap(int y)
{ if(y%4==0&&y%100!=0||y%400==0)
return 1;
else return 0;
}
int main()
{ int m,year,mon,day,all,i;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cin>>m;
while(m--)
{ all=0;
cin>>year>>mon>>day;
if(IsLeap(year)){ month[1]=29;} else month[1]=28;
for(i=0;i cout< }
return 0;
}