int year = 2008; int month = 8; int day = 8; int k,a; /* * 请使用switch语句,if...else语句完成本题 * 如有想看小编思路的,可以点击左侧任务中的“不会了怎么办” * 小编还是希望大家独立完成哦~ */ switch(month) { case 1: a=31; break; case 2: a=31+28; break; case 3: a=31+28+31; break; case 4: a=31+28+31+30; break; case 5: a= 31+28+31+30+31; break; case 6: a=31+28+31+30+31+30; break; case 7: a=31+28+31+30+31+30+31; break; case 8: a=31+28+31+30+31+30+31+31; break; case 9: a=31+28+31+30+31+30+31+31+30; break; case 10: a=31+28+31+30+31+30+31+31+30+31; break; case 11: a=31+28+31+30+31+30+31+31+30+30; break; case 12: a=31+28+31+30+31+30+31+31+30+30+31;break; } if (year%4==0||year%400==0) { k=a+day+1; printf k; } else { k=a+day; printf k; } return 0; }
你写的程序在逻辑上就有问题,首先如果month是一月份,那么case 1:是day,以此类推,另外,在一月份无论是闰年或者平年都是不用加一的