#include<stdio.h>
main(int argc, char *argv[]){
int year, month, day; //define variable
printf("Enter year and month:\n");
scanf("%d,%d", &year, &month);
if((year%4==0)&&(year%100!=0)||(year%400==0))
{
if(month==1)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("Janurary has %d days\n",day);}
else if (month==2)
{ day=29;
printf("The date of this year %d is: 366\n",year);
printf("February has %d days\n",day);}
else if (month==3)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("March has %d days\n",day); }
else if (month==4)
{ day=30;
printf("The date of this year %d is: 366\n",year);
printf("April has %d days\n",day); }
else if (month==5)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("May has %d days\n",day); }
else if (month==6)
{ day=30;
printf("The date of this year %d is: 366\n",year);
printf("Jun has %d days\n",day); }
else if (month==7)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("July has %d days\n",day); }
else if (month==8)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("August has %d days\n",day); }
else if (month==9)
{ day=30;
printf("The date of this year %d is: 366\n",year);
printf("September has %d days\n",day); }
else if (month==10)
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("October has %d days\n",day); }
else if (month==11)
{ day=30;
printf("The date of this year %d is: 366\n",year);
printf("November has %d days\n",day); }
else (month==12);
{ day=31;
printf("The date of this year %d is: 366\n",year);
printf("December has %d days\n",day); }
}
剩下的提交不上去 有字数限制。。。
不过其实思路是一样的
我年份所给出的天数是正确的
问题是无论我输入几月 显示的都是
December has 31 days
不知道问题出在哪里了, 请各位高手 大侠们 指点啊~~!~
看到了一定要说两句 拜托了~~~
我把else 改成 else if
还是不对 问题还和以前一样
终于发现问题了 scanf("%d,%d", &year, &month);
应该把%d,%d 中间的逗号去掉 ^_^
现在又出现新的问题 当我输入年和月 举个例子 输入1988 2
出现 The date of this year 1988 is: 366
February has 29 days
The date of this year 1988 is: 366
December has 31 days
程序似乎是运行了2次不知道怎么回事。。。