作业帮 > 综合 > 作业

C语言:给出年份和月份,计算并显示该年该月的天数

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 11:08:18
C语言:给出年份和月份,计算并显示该年该月的天数
简介,希望能用case:来写
#include
int main()
{
int year,month;
int leap =0;
scanf("%d %d",&year,&month);
if((year %4==0 && year %100 !=0) || year %400 ==0) //闰年2月29天
{
leap=1;
}
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:printf("31");break;
case 4:
case 6:
case 9:
case 11:printf("30");break;
case 2:printf("%d",28+leap);break;
default:printf("error");break;
}
return 0;
}