标签:switch png 某月 logs input 技术分享 main code default
1 #include<stdio.h> 2 #include<stdlib.h> 3 //判断指定的某年某月有多少天 4 void main() 5 { 6 int year,month; 7 int leap,days; 8 printf("please input a year ,month\n"); 9 scanf("%d-%d",&year,&month); 10 if((year%4==0)&&(year%100!=0)||((year%4==0)&&(year%100==0)&&(year%400==0))) 11 leap = 1; 12 else 13 leap = 0; 14 switch(month) 15 { 16 case 1: 17 case 3: 18 case 5: 19 case 7: 20 case 8: 21 case 10: 22 case 12: days = 31;break; 23 case 4: 24 case 6: 25 case 9: 26 case 11: days = 30;break; 27 case 2: days = 28 + leap;break; 28 default :days = 0; 29 30 } 31 if(days == 0) 32 printf("input error!\n"); 33 else 34 printf("%d\n",days); 35 }
标签:switch png 某月 logs input 技术分享 main code default
原文地址:http://www.cnblogs.com/hit-yhj/p/6576111.html