用C语言做一个台历,键盘输入的年号和月号,输出该年该月总天数

(选择――switch语句)
根据键盘输入的年号和月号,输出该年该月总天数。
闰年2月: 29天
闰年的判别条件: 年号能被4整除但不被100整除的年份是闰年 或
年号能被400整除
(year%4 ==0 && year %100!=0) || (year%400==0)
要求:
月份输入不对时,显示提示信息。(1<=month<=12)

#include "Stdio.h"
int main(void)
{ int year,month;
printf("Enter year and month:\n");
scanf("%d,%d",&year,&month);
if(month<1||month>12) printf("fault\n");
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: printf("31 days in this month\n"); break;
case 4:
case 6:
case 9:
case 11:printf("30 days in this month\n");break;
case 2: if((year%4 ==0 && year %100!=0) || (year%400==0))printf("29 days in this month\n");
else printf("28 days in this month\n");
}
return 0;
}

你也太吝啬了,请他人帮忙时一点儿悬赏分都没有。足见你没什么诚意。不过我也闲来无事,就帮你个忙。呵呵~
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-04-20
#include <stdio.h>
void main()
{ int year,month,day; //定义三个整型变量表示年份,月份,天数
printf("input year and month:\n"); //要求输入年份和月份
scanf("%d%d",&year,&month); //将输入的年月放在变量中
switch (month) //对月份分类讨论
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; break; //31天的月份
case 4:
case 6:
case 9:
case 11: day=30; break; //30天的月份
case 2: if ((year % 4 == 0 && year % 100 != 0)
|| year % 400 == 0)
day = 29; //闰年二月28天
else day = 28; break; //非闰年29天
}
if (month < 1 || month >12) printf("error\n");//月份错误,error
else printf("这一月的天数是%d天\n",day); //输出天数
}本回答被提问者采纳
相似回答