求某年某月天数,不是闰年的2月输出也是29天,代码如下图:
改了几次都是这个结果,是不是有什么小点漏了,还是这种写法不好。
请问错误发生在哪里,应该怎么改?
if里面的双引号去掉,如果对你有帮助,麻烦采纳下,谢谢~~~
**输入格式要求:"%d,%d" 提示信息:“Input year,month:” “The number of days is %d\n”
**输出格式要求:"%d"
程序运行示例1如下:
Input year,month:1984,2
The number of days is 29
程序运行示例2如下:
Input year,month:2000,2
The number of days is 29
程序运行示例3如下:
Input year,month:1985,2
The number of days is 28
程序运行示例4如下:
Input year,month:1983,13
Input year,month:1983,-1
Input year,month:1983,1
The number of days is 31
#include<stdio.h>
#define MONTHS 12
int main(void)
{
int days[2][MONTHS] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int year, month;
do
{
printf("Input year,month:");
scanf("%d,%d", &year, &month );
}
while (month < 1 || month > 12);
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
printf("The number of days is %d\n", days[1][month - 1]);
else
printf("The number of days is %d\n", days[0][month - 1]);
return 0;
}