gpt4 book ai didi

c++ - 我不知道如何处理我的日历代码

转载 作者:行者123 更新时间:2023-11-28 04:55:57 25 4
gpt4 key购买 nike

<分区>

我目前正在制作一个日历算法,并且有一个关于它的问题。想请教一下日历,关于在日历上更改月份的第一天。

这是我的日历代码:

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
int days(int year, int month)
{
int days, i;
for (i = 1; i<month; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
{
days = days + 31;
}
else if (i == 4 || i == 6 || i == 9 || i == 11)
{
days = days + 30;
}
else if (i == 2)
{
days = days + 28;
}
}
days = days + 365 * (year - 1980);
return days;
}

int leapyear(int year, int month)
{
int i;
i = (year - 1977) / 4;
if (year % 4 == 0 && month>2)
{
i++;
}
return i;
}

int weekday(int days)
{
int i;
i = days % 7;
return i;
}

void calendar(int year, int month, int week)
{
int i, j, k, d, cal[42] = { 0 };
char m[12][10] = { "January", "February", "March", "April", "May", "June", "July", "Agust", "September", "Octorber", "November", "December" };

switch (month)
{
case 1: d = 31;
break;
case 2:
{
if ((year % 4) == 0) d = 29;
else d = 28;
}
break;
case 3: d = 31;
break;
case 4: d = 30;
break;
case 5: d = 31;
break;
case 6: d = 30;
break;
case 7: d = 31;
break;
case 8: d = 31;
break;
case 9: d = 30;
break;
case 10: d = 31;
break;
case 11: d = 30;
break;
case 12: d = 31;
break;
}

printf(" < %d %s >\n", year, m[month - 1]);
printf("===========================\n");
printf("Sun Mon Tue Wed Thu Fri Sat");
printf("\n---------------------------\n");
j = 1;
for (i = (week + 2) % 7; i<(d + (week + 2) % 7); i++)
{
cal[i] = j;
j++;
}
k = 0;
for (i = 0; i<6; i++)
{
for (j = 0; j<7; j++)
{
if (cal[k] == 0)
{
printf(" ");
}
else
{
printf("%3d ", cal[k]);
}
k++;
}

if (i<5)
{
printf("\n---------------------------\n");
}
else
{
printf("\n===========================\n");
}
}
}

void main()
{
int year, month, total_days, week;
char YN = 'Y';
do
{
printf("entered year and month with 1980 ~ 2030.(EX) :2003 5)\n");
scanf_s("%d %d", &year, &month);
if (year >= 1980 && year <= 2030 && month >= 1 && month <= 12)
{
printf("Your entered %dYear %dMonth.\n", year, month);
total_days = days(year, month) + leapyear(year, month);
week = weekday(total_days);
calendar(year, month, week);
}
printf("Retry It?(Y/N):");
YN = _getche();
printf("\n");
} while (YN != 'N');
}

我希望这些结果出来:

 < 2003 May >

Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31


Retry It?(Y/N):

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com