定义一个含年,月,日的结构体,输入一个日期,计算该日期是该年的第多少天
1个回答
展开全部
#include<stdio.h>
int main( )
{
struct dd{int y,m,d;}date;
int i,j,k;
scanf("%d%d%d",&date.y,&date.m,&date.d);
k=date.d;
if(date.m>1)k+=31;
if(date.m>2)k+=28;
if(date.m>3)k+=31;
if(date.m>4)k+=30;
if(date.m>5)k+=31;
if(date.m>6)k+=30;
if(date.m>7)k+=31;
if(date.m>8)k+=31;
if(date.m>9)k+=30;
if(date.m>10)k+=31;
if(date.m>11)k+=30;
if(date.y%4==0&&date.y%100!=0||date.y%400==0)k++;
printf("%d-%d-%d is No.%d day in %d.\n",date.y,date.m,date.d,k,date.y);
getch();
}
int main( )
{
struct dd{int y,m,d;}date;
int i,j,k;
scanf("%d%d%d",&date.y,&date.m,&date.d);
k=date.d;
if(date.m>1)k+=31;
if(date.m>2)k+=28;
if(date.m>3)k+=31;
if(date.m>4)k+=30;
if(date.m>5)k+=31;
if(date.m>6)k+=30;
if(date.m>7)k+=31;
if(date.m>8)k+=31;
if(date.m>9)k+=30;
if(date.m>10)k+=31;
if(date.m>11)k+=30;
if(date.y%4==0&&date.y%100!=0||date.y%400==0)k++;
printf("%d-%d-%d is No.%d day in %d.\n",date.y,date.m,date.d,k,date.y);
getch();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询