岔的形近字:输入年和月,判断是润年或不是润年,并输出月的天数,如果是润年,2月就输出29天,如果不是润处就输出28天

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/11 03:42:40
输入年和月,判断是润年或不是润年,并输出月的天数,月大31月小30,如果是润年,2月就输出29天,如果不是润年就输出28天
用turbo c 的if语句或switch语句来编。

#include "stdio.h"
main()
{
int IsYear(int);/*函数原形声明*/
int curyear=0; /*输入年*/
int curmonth=0; /*输入月*/
printf("Please input the year and month:\n");
scanf("%d%d",&curyear,&curmonth);
if (curyear<=0)
{printf("Year is not true!\n");
exit (0);} /* 年份输入错误,退出程序*/
if (curmonth<=0 || curmonth>12)
{ printf("Month is not true month!\n");
exit (0);} /*月份输入错误,退出程序*/
switch (curmonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("it has 31 days\n");
break;
case 4:
case 6:
case 9:
case 11:
printf("it is small month: 30 days\n");
break;
case 2:
if (IsYear(curyear))
printf("It is run nian:29 days\n");
else
printf("it is ping nian: 28 days\n");
break;
}
}
/*检测是否是闰年*/
/*返回1时则是闰年,否则是平年*/
int IsYear(int year)
{ int flag=0;
if (year%4==0)
if (year % 100==0)
if (year % 400==0)
flag=1;
else
flag=0;
else
flag=1;
else
flag=0;

return (flag);
}
OK,到此程序已经成功完成你要的功能,别忘了给我加分哦.