#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]);
}
C语言,输入年月日,返回总天数,可改写成打印一个月中的假期天数。
最新推荐文章于 2024-05-30 21:35:46 发布