-
Notifications
You must be signed in to change notification settings - Fork 16
/
8.c
71 lines (60 loc) · 1.45 KB
/
8.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
67
68
69
70
71
#include <stdio.h>
struct date
{
int day;
int month;
int year;
};
int compareDates(struct date date1, struct date date2)
{
int yearDiff = date1.year - date2.year;
int monthDiff = date1.month - date2.month;
int dayDiff = date1.day - date2.day;
if (yearDiff < 0)
return 1;
else if (yearDiff > 0)
return 0;
else
{
if (monthDiff < 0)
return 1;
else if (monthDiff > 0)
return 0;
else
{
if (dayDiff < 0)
return 1;
else if (dayDiff > 0)
return 0;
else
return -1; // Dates gulo same hobe
}
}
}
int main()
{
struct date date1, date2;
int result;
printf("Enter the first date:\n");
printf("Enter the day: ");
scanf("%d", &date1.day);
printf("Enter the month: ");
scanf("%d", &date1.month);
printf("Enter the year: ");
scanf("%d", &date1.year);
printf("\nEnter the second date:\n");
printf("Enter the day: ");
scanf("%d", &date2.day);
printf("Enter the month: ");
scanf("%d", &date2.month);
printf("Enter the year: ");
scanf("%d", &date2.year);
result = compareDates(date1, date2);
if (result == 1)
printf("\nDate 1 is earlier than Date 2\n");
else if (result == 0)
printf("\nDate 1 is later than Date 2\n");
else
printf("\nDate 1 is the same as Date 2\n");
return 0;
}