-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path4.c
55 lines (51 loc) · 1.02 KB
/
4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//输入某年某月某日,判断这一天是这一年的第几天?
#include<stdio.h>
#include<windows.h>
#pragma warning(disable:4996)
int main()
{
int year, month, day;
int sum = 0;
printf("请输入年月日:\n");
scanf("%d%d%d", &year, &month, &day);
switch (month)
{
case 1:sum = 0;
break;
case 2:sum = 31;
break;
case 3:sum = 31 + 28;
break;
case 4:sum = 31 + 28 + 31;
break;
case 5:sum = 31 + 28 + 31 + 30;
break;
case 6:sum = 31 + 28 + 31 + 30 + 31;
break;
case 7:sum = 31 + 28 + 31 + 30 + 31 + 30;
break;
case 8:sum = 31 + 28 + 31 + 30 + 31 + 30 + 31;
break;
case 9:sum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
break;
case 10:sum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
break;
case 11:sum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
break;
case 12:sum = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
break;
default:
break;
}
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (month >= 2)
{
sum++;
}
}
sum += day;
printf("%d\n", sum);
system("pause");
return 0;
}