-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.c
40 lines (23 loc) · 850 Bytes
/
2.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
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
int dateDifference(struct Date d1, struct Date d2) {
int days1 = d1.year * 365 + d1.month * 30 + d1.day;
int days2 = d2.year * 365 + d2.month * 30 + d2.day;
int difference = (days1 > days2) ? (days1 - days2) : (days2 - days1);
return difference;
}
int main() {
struct Date date1;
printf("Enter the first date (day month year): ");
scanf("%d %d %d", &date1.day, &date1.month, &date1.year);
struct Date date2;
printf("Enter the second date (day month year): ");
scanf("%d %d %d", &date2.day, &date2.month, &date2.year);
int diff = dateDifference(date1, date2);
printf("The difference between the two dates is %d days.\n", diff);
return 0;
}