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

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#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]);
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值