//输入一个月份,计算这个月份的天数 #include<stdio.h> int main() { int year,mon; int leap; int days; printf("输入年份、月份:\n"); scanf("%d %d",&year,&mon); fun(year); switch(mon) { case 1: days = 31; break; case 2: if(leap == 1) days = 28; else days = 29; break; case 3: days = 31; break; case 4: days = 30; break; case 5: days = 31; break; case 6: days = 30; break; case 7: days = 31; break; case 8: days = 31; break; case 9: days = 30; break; case 10: days = 31; break; case 11: days =30; break; case 12: days = 31; break; default: printf("你来自火星!\n"); break; } printf("%d\n",days); return 0; } fun (int year) //用来判断输入的年份是闰年还是非闰年; { int flag = 0; //不是闰年; int leap; if(year % 4 == 0) { if(year % 100) { if(year % 400 == 0) { flag =1; } } else { flag = 1; } } else { flag = 0; } if(flag == 1) { leap = 1; } else { leap = 0; } }