Calculate the number of days: Enter the date, find the day is the day of that year?

#include <stdio.h>

void main() {
    int y, m, d, s, i;
    scanf("%d%d%d", &y, &m, &d);
    s = d;
    for (i = 1; i < m; i++)
        if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
            s += 31;
        else if (i == 4 || i == 6 || i == 9 || i == 11)
            s += 30;
        else if (i == 2 && (y % 4 == 0 && y % 100 != 0 || y % 400 == 0))
            s += 29;
        else
            s += 28;
    printf("%d", s);
}
Published 139 original articles · won praise 4 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104784998