c语言编程:输入某年某月某日,计算出这一天是该年的第几天?该怎么解答啊

2024-11-25 14:12:32
推荐回答(3个)
回答1:

//输入年月日,输出是该年第几天
#include
int sum(int month,int day)
{
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i;
for(i=1;iday+=days[i];
return(day);
}

int leap(year)
{
int leap=0;
if((year%4==0&&year%100!=0)||(year%400==0))
leap=1;
return leap;
}

void main()
{
int year,month,day,num;
printf("Please input year,month,day:\n");
scanf("%d,%d,%d",&year,&month,&day);
num=sum(month,day);
if(leap(year)&&month>=3)
num++;
printf("It is the %dth day.\n",num);
}

回答2:

//输入年月日,输出是该年第几天
#include
int
sum(int
month,int
day)
{
int
days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int
i;
for(i=1;iday+=days[i];
return(day);
}
int
leap(year)
{
int
leap=0;
if((year%4==0&&year%100!=0)||(year%400==0))
leap=1;
return
leap;
}
void
main()
{
int
year,month,day,num;
printf("Please
input
year,month,day:\n");
scanf("%d,%d,%d",&year,&month,&day);
num=sum(month,day);
if(leap(year)&&month>=3)
num++;
printf("It
is
the
%dth
day.\n",num);
}

回答3:

这个,如果傻一点点可以用个循环从1月1日起来始累加,直到加到等于你的这个日期为止