酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

C语言实现:计算指定日期在本年中是第几天的函数days()

```c #include <stdio.h> struct Date { int year; int month; int day; }; int days(struct Date date) { int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int dayCount = 0; for (int i = 0; i < date.month - 1; i++) { dayCount += daysInMonth[i]; } dayCount += date.day; if ((date.year % 400 == 0 || (date.year % 4 == 0 && date.year % 100!= 0)) && date.month > 2) { dayCount++; } return dayCount; } int main() { struct Date date = {2011, 2, 1}; int day = days(date); printf("2011 年 2 月 1 日是该年的第 %d 天\n", day); return 0; } ``` ######[AI写代码神器 | 281点数解答 | 2024-09-25 22:39:03]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]