栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言,输入年月日,返回总天数,可改写成打印一个月中的假期天数。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言,输入年月日,返回总天数,可改写成打印一个月中的假期天数。

#include
#include
#include
#define AS 12
#define QW 20
#define SS 7
struct as {
	char w[AS];
};
struct qw {
	int q;
	int h;
	int o;
};
struct yu {
	char* s[2];
	char aa[2];
};
void qq(void);
int gg(struct as v, struct qw r);
void jj(struct yu z, struct qw y);
int main(void)
{
	double b;
	double n;
	struct qw e;
	char* k, * l;
	struct as y = { {31,28,31,30,31,30,31,31,30,31,30,31} };
	char m[AS] = "元旦假期:";
	char mm[AS] = "除夕假期:";
	l = mm;
	k = m;
	struct yu yi = { {k,l},{3,1} };
	while (1)
	{
		printf("请输入年份:");
		scanf_s("%d", &e.q);
		if (e.q ==0)
		{
			printf("退出程序。");
			exit(EXIT_FAILURE);
		}
		printf("请输入月份:");
		scanf_s("%d", &e.h);
		while ((e.h > 12) || (e.h <= 0))
		{
			printf("月份输入错误!");
			printf("请重新输入:");
			scanf_s("%d", &e.h);
		}
		printf("请输入日期:");
		scanf_s("%d", &e.o);
			while ((e.o > y.w[e.h-1])||(e.o<=0))
			{
				printf("日期输入错误!");
				printf("请重新输入:");
				scanf_s("%d", &e.o);
			}
		b = gg(y, e);
		n = b / SS;
		printf("从去年12月31日至今已过 %.f 天,大约 %.2f 个星期。n", b, n);
		if (e.h == 1)
		{
			jj(yi, e);
		}
		if (b == 365)
		{
			printf("新的一年即将到来,新年新气象,祝你新年元气满满!!n");
		}
		if ((e.h == 5) && (e.o == 1))
		{
			printf("五一劳动节快乐,祝你节日快乐!n");
		}
		puts("祝你生活快乐,开心面对每一天!");
		printf("n");
	}
	return 0;
}
void qq(void)
{
	while (getchar() != 'n')
		continue;
}
int gg(struct as v, struct qw r)
{
	int u = 0;
	if (r.h > 1)
	{
		for (int a = 0; a < r.h-1; a++)
		{
			u += v.w[a];
		}
	}
	u += r.o;
	return u;
}
void jj(struct yu z, struct qw y)
{
	printf("在 %d 月中假期:", y.h);
	printf("%s假期有 %d 天! ", z.s[0], z.aa[0]);
	printf("%s假期有 %d 天!n", z.s[1], z.aa[1]);
	printf("1月假期一共有 %d 天n", z.aa[0] + z.aa[1]);
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/847431.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号