-
Notifications
You must be signed in to change notification settings - Fork 0
/
Consecutive months (enum & struct) C
84 lines (63 loc) · 1.76 KB
/
Consecutive months (enum & struct) 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
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
typedef enum month {jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec} month;
typedef struct date {month mth; int day;} date;
int last, con;
void today (date* pass)
{
switch (pass->mth)
{
case jan: printf("January %d", pass->day);
break;
case feb: printf("February %d", pass->day);
break;
case mar: printf("March %d", pass->day);
break;
case apr: printf("April %d", pass->day);
break;
case may: printf("May %d", pass->day);
break;
case jun: printf("June %d", pass->day);
break;
case jul: printf("July %d", pass->day);
break;
case aug: printf("August %d", pass->day);
break;
case sep: printf("September %d", pass->day);
break;
case oct: printf("October %d", pass->day);
break;
case nov: printf("November %d", pass->day);
break;
case dec: printf("December %d", pass->day);
break;
}
}
date*tomorrow(date*pass)
{
if(pass->day==last)
{
pass->day=(pass->day+1)%last;
pass->mth=(pass->mth+1)%12;
}
else
pass->day=pass->day+1;
return 0;
}
int main()
{
date first_date={jan, 1};
date second_date={feb, 28};
date third_date={mar,14};
date fourth_date={oct, 31};
date fifth_date={dec, 1};
date dates[]={first_date, second_date, third_date, fourth_date, fifth_date};
for(con=0; con<5;con++)
{
printf("the date is");
today(&dates[con]);
printf("\n the next day is");
tomorrow(&dates[con]);
today(&dates[con]);
}
return 0;
}