用C语言计算a年b月有多少天,怎么弄啊
发布网友
发布时间:2023-03-07 14:49
我来回答
共1个回答
热心网友
时间:2023-10-08 18:09
#include <stdio.h>
int main(void)
{
int year, mouth;
int num;
printf("Input year: ");
scanf("%d", &year);
printf("Input mouth: ");
scanf("%d", &mouth);
num = 0;
switch( mouth )
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
num = 31; break;
case 4: case 6: case 9: case 11:
num = 30; break;
case 2:
if( (year%400 == 0) || (year%4 == 0 && year%100 != 0))
num = 29;
else
num = 28;
break;
default: num = 0;
printf("Input error mouth.\n");
num = 0; break;
}
if( num != 0)
printf("There are %d days in %d mouth.\n", num, mouth);
return 0;
}