c语言程序设计:编写函数1实现判断是不是闰年,编写函数2用于输出某年某月的天数

如题所述

c语言程序:
#include <stdio.h>
int RY(int Y){
if ((Y%4==0)&&(Y%100!=0)||(Y%400==0)) return 1;
else return 0;
}
int DYM(int Y, int M){
const short MonthDay[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (M==2) return (MonthDay[2]+RY(Y));
else return MonthDay[M];
}

int main()
{
int year, month;
printf("input year month 2016 2:\n");
scanf("%d %d",&year,&month);
if (RY(year)==1) printf("leap year\n"); else printf("No leap\n");
printf("%d-%02d: %d days\n",year, month, DYM(year,month));
return 0;
}
---
函数 int RY(int Y); 输入年,闰年返回1,非 闰年返回 0。
函数 int DYM(int Y, int M); 输入年月,返回该月天数。
(程序未考虑对输入数据的合理性作检查。)
温馨提示:答案为网友推荐,仅供参考
相似回答