
#include <stdio.h>
#include <stdlib.h> //system("pause")
main()
{
int year, month, day, total, leap; //total总天数 ,leap用于闰年的2月天数
scanf("%d%d%d", &year, &month, &day);
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) //判断是否闰年,闰年2月多一天,所以闰年leap为1,平年为leap为0。
{
leap = 1;
}
else
{
leap = 0;
}
switch (month) //根据月份计算对应的最终天数。
{
case 1:
total = day;
break;
case 2:
total = 31 * 1 + day;
break;
case 3:
total = 31 * 1 + 28 + leap + day;
break;
case 4:
total = 31 * 2 + 28 + leap + day;
break;
case 5:
total = 31 * 2 + 28 + leap + 30 * 1 + day;
break;
case 6:
total = 31 * 3 + 28 + leap + 30 * 1 + day;
break;
case 7:
total = 31 * 3 + 28 + leap + 30 * 2 + day;
break;
case 8:
total = 31 * 4 + 28 + leap + 30 * 2 + day;
break;
case 9:
total = 31 * 5 + 28 + leap + 30 * 2 + day;
break;
case 10:
total = 31 * 5 + 28 + leap + 30 * 3 + day;
break;
case 11:
total = 31 * 6 + 28 + leap + 30 * 3 + day;
break;
case 12:
total = 31 * 6 + 28 + leap + 30 * 4 + day;
break; //12月之前的11个月中有6个31天,4个30天,2月为28天+leap。
}
if (year >= 1 && year <= 9999 && month >= 1 && month <= 12 && day >= 1 && day <= 31) //判断输入是否正解,年份最大为9999,可自行更改。
{
printf("%d\n",total);
}
else
{
printf("\n\t错误\n\n");
}
return 0;
}
#include<stdio.h>
int dm(int year,int month, int day)
{
int flag=0;
if((year%4==0 && year%100!=0) || (year%400==100))flag = 1;
else flag =0;
int a=0;
switch(month-1)
{
case 11 :a+=30;
case 10 :a+=31;
case 9 :a+=30;
case 8 :a+=31;
case 7 :a+=31;
case 6 :a+=30;
case 5 :a+=31;
case 4 :a+=30;
case 3 :a+=31;
case 2 :a+=28+flag;
case 1 :a+=31;break;
default :printf("Please input others\n");
}
a +=day;
printf("%d \n",a,year);
}
int main()
{
int day,month,year;
printf("请输入年 月 日:\n");
scanf("%d %d %d",&year,&month,&day);
dm(year,month,day);
return 0;
}