-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex.11.11.c
81 lines (62 loc) · 1.42 KB
/
ex.11.11.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
// Program to determine tomorrow's date
#include <stdio.h>
#include <stdbool.h>
struct date
{
int month;
int day;
int year;
};
// Function to calculate tomorrow's date
void dateUpdate (struct date *today)
{
int numberOfDays (struct date d);
if ( today->day != numberOfDays (*today) ) {
today->day++;
}
else if ( today->month == 12 ) { // end of year
today->day = 1;
today->month = 1;
today->year++;
}
else { // end of month
today->day = 1;
today->month++;
}
}
// Function to find the number of days in a month
int numberOfDays (struct date d)
{
int days;
bool isLeapYear (struct date d);
const int daysPerMonth[12] = {
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
};
if ( isLeapYear (d) == true && d.month == 2 )
days = 29;
else
days = daysPerMonth[d.month - 1];
return days;
}
// Function to determine if it's a leap year
bool isLeapYear (struct date d)
{
bool leapYearFlag;
if ( (d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0 )
leapYearFlag = true; // It's a leap year
else
leapYearFlag = false; // Not a leap year
return leapYearFlag;
}
int main (void)
{
void dateUpdate (struct date *today);
struct date thisDay;
printf ("Enter today's date (mm dd yyyy): ");
scanf ("%i%i%i", &thisDay.month, &thisDay.day, &thisDay.year);
dateUpdate (&thisDay);
printf ("Tomorrow's date is %i/%i/%.2i.\n", thisDay.month,
thisDay.day, thisDay.year % 100);
return 0;
}