东北大学在线编程社区problem1515
题目描述:
定义一个日期结构体类型(包括年、月、日),编写程序,要求输入年月日,输出该日在本年中第几天。
输出格式:"是%d年第%d天"
输入样例:2006 3 12
输出样例:
是2006年第71天
//本次使用CodeBlocks 20.03编写代码
#include<stdio.h>
struct day{
int year;
int month;
int date;
};
int main(void)
{
struct day d;
scanf("%d%d%d",&d.year,&d.month,&d.date);
int m,n=0,i,j,k,a=0;
if(d.year%4==0){
if(d.year%100!=0){
a=1;
}
}
if(d.year%400==0)
a=1;
for(i=1;i<d.month;i++){
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
m=31;
break;
case 4:
case 6:
case 9:
case 11:
m=30;
break;
}
if(i==2){
if(a)
m=29;
else
m=28;
}
n+=m;
}
n+=d.date;
printf("是%d年第%d天",d.year,n);
return 0;
}