#include <stdio.h>

int isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { return 1; } return 0; }

int main() { printf("Enter year month day:");

int year, month, day;

int daysOfMonth[2][13] = {
    {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

scanf("%d%d%d", &year, &month, &day);

int days = 0;

for (int i = 1; i < month; i++)
{
    days += daysOfMonth[isLeapYear(year)][i];
}

days += day;

printf("day of year is %d", days);

return 0;

}

C语言程序:计算一年中的第几天

原文地址: https://www.cveoy.top/t/topic/plZ3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录