-
Notifications
You must be signed in to change notification settings - Fork 0
/
test11.c
66 lines (64 loc) · 1.15 KB
/
test11.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
55
56
57
58
59
60
61
62
63
64
65
66
// Check day valid
// Leap year: y % 400 == 0 or ( y % 4 == 0 and y % 100 !=0 )
// Input: 14 2 2023
// Output: valid day
#include <stdio.h>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fod(i, a, b) for (int i = b; i >= a; i--)
int d, m, y;
int validDate(int d, int m, int y)
{
// Check valid year
if (y < 0 || y > 2023)
{
return 0;
}
// Check valid month
if (m < 1 || m > 12)
{
return 0;
}
// Check valid day
if (d < 1)
{
return 0;
}
else if (m == 2)
{
if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0))
{
if (d > 29)
{
return 0;
}
}
else
{
if (d > 28)
{
return 0;
}
}
}
else if (m == 4 || m == 6 || m == 9 || m == 11)
{
if (d > 30)
{
return 0;
}
}
else
{
if (d > 31)
{
return 0;
}
}
return 1;
}
int main()
{
scanf("%d %d %d", &d, &m, &y);
validDate(d, m, y) ? printf("valid date") : printf("invalid date");
return 0;
}