思路:
为衡阳等地区用户提供了全套网页设计制作服务,及衡阳网站建设行业解决方案。主营业务为网站建设、做网站、衡阳网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!1. 编写函数判断平年闰年
2. 编写函数获得某年某月的天数
3. 编写函数判断这一年距离公元1年相差多少天
4. 编写函数判断某年某月距离公元1年1月相差多少天
5. 编写函数打印某一年12个月份的日历
6. 编写函数打印某年某月的月历
7. 编写函数查询某个日期为星期几,什么节日
运行图:
源代码:
#include#includestatic char week[7][7] = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
static char month[12][10] = {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
int IsLeapYear(int year)
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
return 1;
return 0;
}
int GetMonDays(int year, int mon)
{
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (mon == 2 && (IsLeapYear(year) == 1))
{
return 29;
}
return days[mon];
}
long DaysY(int year)
{
long sum = 0;
int i;
for (i = 1; i< year; i++)
{
if (IsLeapYear(i) == 1)
sum += 366;
else
sum += 365;
}
return sum;
}
long DaysM(int year, int mon)
{
long sum = DaysY(year);
int i;
for (i = 1; i< mon; i++)
{
sum += GetMonDays(year, i);
}
return sum;
}
void ShowM(int year, int mon)
{
long sum = DaysM(year, mon);
int ret = sum % 7;
int temp = 7 - ret;
int i;
printf("\n %6s\n", month[mon - 1]);
printf("--------------------------------------------------\n");
for (i = 0; i< 7; i++)
{
printf("| %5s ", week[i]);
}
printf("|\n");
for (i = 0; i< 7; i++)
{
printf("|------");
}
printf("|\n");
for (i = 0; i< ret; i++)
{
printf("| ");
}
for (i = 1; i<= GetMonDays(year, mon); i++)
{
printf("|%4d ", i);
if (i == temp || (i - temp) % 7 == 0)
{
printf("|\n");
int j;
for (j = 0; j< 7; j++)
{
printf("|------");
}
printf("|\n");
}
}
if ((ret + GetMonDays(year, mon)) % 7 != 0)
{
printf("|\n");
}
ret = ((GetMonDays(year, mon)) % 7 + ret) % 7;
for (i = 0; i< ret; i++)
{
printf("|------");
}
if (ret != 0)
{
printf("|\n");
}
}
void ShowY(int year)
{
printf(" 万年历??%d年\n",year);
printf(" ***********************************************\n");
int i;
for (i = 0; i< 12; i++)
{
ShowM(year, i + 1);
printf("\n");
}
}
void menu()
{
printf(" ***********************************************\n");
printf(" ****************** 1.查询某年 *************\n");
printf(" ****************** 2.查询某年某月 *************\n");
printf(" ****************** 3.查询年月日 *************\n");
printf(" ****************** 0.退出查询 *************\n");
printf(" ***********************************************\n");
}
int main()
{
int input;
int year, mon, day;
do
{
menu();
printf("\n请选择:>");
scanf("%d", &input);
system("clear");
switch (input)
{
case 1:
printf("请输入需要查询的年份:>");
while (~scanf("%d", &year))
{
if (year >= 1)
{
system("clear");
ShowY(year);
printf("请输入需要查询的年份:>");
}
else if (year == 0)
{
printf("退出年份查询\n\n");
break;
}
else
{
printf("查询超出范围,请重新输入:>");
}
}
break;
case 2:
printf("请输入需要查询的年月:>");
while(~scanf("%4d%2d", &year, &mon))
{
if (year >= 1)
{
ShowM(year, mon);
printf("\n请输入需要查询的年月:>");
}
else if (year == 0 || mon == 0)
{
printf("退出年月查询\n\n");
break;
}
else
{
printf("查询超出范围");
}
}
break;
case 3:
printf("请输入需要查询的日期:>");
while(~scanf("%4d%2d%2d", &year, &mon, &day))
{
if (year >= 1 && mon<= 12 && day<= GetMonDays(year, mon))
{
long sum = DaysM(year, mon) + day;
int ret = sum % 7;
if (ret == 0)
ret = 7;
printf("%7s\n", week[ret - 1]);
if (mon == 1 && day == 1)
printf("元旦节");
else if (mon == 2 && day == 14)
printf("情人节");
else if (mon == 3 && day == 8)
printf("妇女节");
else if (mon == 4 && day == 1)
printf("愚人节");
else if (mon == 5 && day == 1)
printf("劳动节");
else if (mon == 6 && day == 1)
printf("儿童节");
else if (mon == 7 && day == 1)
printf("建党节");
else if (mon == 8 && day == 1)
printf("建军节");
else if (mon == 10 && day == 1)
printf("国庆节");
else if (mon == 10 && day == 31)
printf("万圣夜");
else if (mon == 11 && day == 24)
printf("感恩节");
else if (mon == 12 && day == 25)
printf("圣诞节");
printf("\n\n");
printf("请输入需要查询的日期: >");
}
else if (year == 0 || mon == 0 || day == 0)
{
printf("退出日期查询\n\n");
break;
}
else
printf("超出查询范围,请重新输入:>");
}
case 0:
break;
default:
printf("输入错误,请重新选择:>");
break;
}
} while (input);
return 0;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧