c语言编程:输入某年某月某日,计算出这一天是该年的第几天?该怎么解答啊
3个回答
展开全部
//输入年月日,输出是该年第几天
#include<stdio.h>
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;i<month;i++)
day+=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);
}
#include<stdio.h>
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;i<month;i++)
day+=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);
}
展开全部
//输入年月日,输出是该年第几天
#include<stdio.h>
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;i<month;i++)
day+=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);
}
#include<stdio.h>
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;i<month;i++)
day+=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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个,如果傻一点点可以用个循环从1月1日起来始累加,直到加到等于你的这个日期为止
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询