如何计算闰年DAY?

时间:2012-10-04 14:59:19

标签: c

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

# 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;
}

1 个答案:

答案 0 :(得分:0)

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

但我想你的问题是找到一周中的某一天,无论哪一天。

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