-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprog.9.2.c
44 lines (36 loc) · 875 Bytes
/
prog.9.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
41
42
43
44
// Program to determine tomorrow's date
#include <stdio.h>
int main (void)
{
struct date
{
int month;
int day;
int year;
};
struct date today, tomorrow;
const int daysPerMonth[12] = {
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
};
printf ("Enter today's date (mm dd yyyy): ");
scanf ("%i%i%i", &today.month, &today.day, &today.year);
if ( today.day != daysPerMonth[today.month - 1] ) {
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else if ( today.month == 12 ) { // end of year
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
else { // end of month
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
printf ("Tomorrow's date is %i/%i/%.2i.\n", tomorrow.month,
tomorrow.day, tomorrow.year % 100);
return 0;
}