-3

所以用户输入年份+它告诉它是否是闰年..但现在我需要帮助让一周中的一天在闰年时弹出。

# include <math.h>
# include <stdio.h>

int main (void)
{
    int yearEntered;

    printf("Enter a year: ");

    int read = scanf("%d", &yearEntered);

    if (read == 0 )
    {
        printf("Bad input: requires an integer");
    }
    else if (yearEntered%4==0 && yearEntered%100!=0 || yearEntered%400==0)
    {
        printf("%04d is a leap year and February 29th is on a \n",yearEntered, dayString);

    // Not so sure about this switch statement......
    switch (DayOfWeek)
    {
        case 0:
        {
            dayString("Sunday");
            break;
        }
        case 1:
        {
            dayString("Monday");
            break;
        }
        case 2:
        {
            dayString("Tuesday");
            break;
        }
        case 3:
        {
            dayString("Wednesday");
            break;
        }
        case 4:
        {
            dayString("Thursday");
            break;
        }
        case 5:
        {
            dayString("Friday");
            break;
        }
        case 6:
        {
            dayString("Saturday");
            break;
        }
        default:
        {
            dayString("");
        }

    }

    else if (yearEntered < 1752)
    {
        printf("%04d is not a 4 digit year after 1752.",yearEntered);
    }
    else
    {
        printf("%d is not a leap year.\n",yearEntered);
    }

    return 0;
}
4

1 回答 1

0

如果您的问题只是 2 月 29 日的星期几,您只需要计算 2 月 28 日的星期几并增加它(当然是模 7)。

但我想你的问题是找到星期几,不管是哪一天。

在这种情况下,您可能会对 Wikipedia 所说的内容感兴趣:Determination of the day of week

于 2012-10-04T15:15:32.173 回答