1 #include<stdio.h>
 2 
 3 int main(void)
 4 {
 5     int year;
 6     int month;
 7     int day;
 8     int a[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 9     int days = 0;
10 
11     scanf_s("%d/%2d/%2d", &year, &month, &day);
12 
13     if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
14     {
15         a[1] = 29;
16     }
17     
18     for (int i = 1; i < month; i++)
19     {
20         days = days + a[i];
21     }
22 
23     days = days + day;
24 
25     printf("%d\n", days);
26 
27     return 0;
28 }

计算天数,用了数组。

版权声明:本文为2018jason原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/2018jason/p/11798663.html