如何获得本月的第一天和最后一天的日期
1个回答
展开全部
年和月知道了,第一天显然就是1号了,最后一天根据闫年和月份判断:
#define isleap(y) ((y)%4 == 0 && (y)%100 != 0 || (y)%400 == 0)
int year,month;
scanf("%d,%d", &year, &month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31");
break;
case 2:
if (isleap(year))
printf("29");
else
printf("28");
break;
case 4:
case 6:
case 9:
case 11:
printf("30");
break;
default:
printf("error");
}
#define isleap(y) ((y)%4 == 0 && (y)%100 != 0 || (y)%400 == 0)
int year,month;
scanf("%d,%d", &year, &month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31");
break;
case 2:
if (isleap(year))
printf("29");
else
printf("28");
break;
case 4:
case 6:
case 9:
case 11:
printf("30");
break;
default:
printf("error");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询