#include <stdio.h>
#include <math.h>
void main(){suasua
int a,b,c,d;
printf("pls input year/m/d:\n");
scanf("%d %d %d",&a,&b,&c);
switch (b) {
case 1:
printf("is %ddays\n",c);
break;
}
if(((a%4==0&&a%100!=0)||(a%400==0))&&(2<b||2==b)){
switch (b) {
case 2:
printf("is %ddays\n",d=31+c);break;
case 3:
printf("is %ddays\n",d=60+c);break;
case 4:
printf("is %ddays\n",d=91+c);break;
case 5:
printf("is %ddays\n",d=121+c);break;
case 6:
printf("is %ddays\n",d=152+c);break;
case 7:
printf("is %ddays\n",d=182+c);break;
case 8:
printf("is %ddays\n",d=213+c);break;
case 9:
printf("is %ddays\n",d=244+c);break;
case 10:
printf("is %ddays\n",d=274+c);break;
case 11:
printf("is %ddays\n",d=305+c);break;
case 12:
printf("is %ddays\n",d=335+c);break;
break;
}
}else{
switch (b) {
case 2:
printf("is %ddays\n",d=31+c);break;
case 3:
printf("is %ddays\n",d=59+c);break;
case 4:
printf("is %ddays\n",d=90+c);break;
case 5:
printf("is %ddays\n",d=120+c);break;
case 6:
printf("is %ddays\n",d=151+c);break;
case 7:
printf("is %ddays\n",d=181+c);break;
case 8:
printf("is %ddays\n",d=212+c);break;
case 9:
printf("is %ddays\n",d=243+c);break;
case 10:
printf("is %ddays\n",d=273+c);break;
case 11:
printf("is %ddays\n",d=304+c);break;
case 12:
printf("is %ddays\n",d=334+c);
break;
}
}
}
算法思想:设定结构体类型表示日期类型名为Date,将其定义为日期类型名,用三个整形变量分别表示年月日。
设定函数判断年份是否为闰年来决定二月份的天数。根据输入的日期月份,在数组中将相应的月份天数求和,程序由6个函数构成。