-
Notifications
You must be signed in to change notification settings - Fork 16
/
7.c
54 lines (41 loc) · 1.08 KB
/
7.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
#include <stdio.h>
struct date
{
int day;
int month;
int year;
};
struct date nextdate(struct date presentDate, int days)
{
int daysInMonth;
presentDate.day += days;
daysInMonth = getDaysInMonth(presentDate.month, presentDate.year);
if (presentDate.day > daysInMonth)
{
presentDate.day = presentDate.day % daysInMonth;
presentDate.month++;
if (presentDate.month > 12)
{
presentDate.month = 1;
presentDate.year++;
}
}
return presentDate;
}
int main()
{
struct date presentDate, nextDate;
int daysToAdd;
printf("Enter the present date:\n");
printf("Enter the day: ");
scanf("%d", &presentDate.day);
printf("Enter the month: ");
scanf("%d", &presentDate.month);
printf("Enter the year: ");
scanf("%d", &presentDate.year);
printf("Enter the number of days to add: ");
scanf("%d", &daysToAdd);
nextDate = nextdate(presentDate, daysToAdd);
printf("The next date is: %02d-%02d-%04d\n", nextDate.day, nextDate.month, nextDate.year);
return 0;
}