帮忙改改一段简单的程序,程序的作用是读入一个年份和月份,打印出该月有多少天

来源:百度知道 编辑:UC知道 时间:2024/09/25 09:30:03
程序代码如下
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{ int year ;
int month;

printf("please input year and month :");
scanf("%d,%d",&year,&month );
switch(month);
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31 days\n");
break;
case 2:
if ((year%4==0&&year%100!=0)||(year%400==0))
{ printf("29 days\n" );
}
else
{ printf("28 days\n");
}
break;

case 4:
case 6:
case 9:
case 11:
printf("30 days \n");

把你的程序中那句switch(month);中的分号去了就行了
改成switch(month)

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main()
{
int year ;
int month;
printf("please input year and month :");
scanf("%d%d",&year,&month ); //格式里面不要含有逗号
switch(month) //去除分号
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("31 days\n");
break;
case 2:
if ((year%4==0&&year%100!=0)||(year%400==0))
{
printf("29 days\n" );
}
else
{
printf("28 days\n");
}
break;
case 4:
case 6:
case 9:
case 11:
printf("30 days \n");
break;
default:
printf("Input Erro!");
}
system("pause");
return 0;//添加返回值