-
Notifications
You must be signed in to change notification settings - Fork 0
/
structdays.c
47 lines (40 loc) · 1.31 KB
/
structdays.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
#include <stdio.h>
// Create a structure named Date having day, month and year as its elements.
// Store the current date in the structure.
// Now add 50 days to the current date and display the final date.
void main() {
struct Date {
int day;
int month;
int year;
} dates;
printf("Enter Current Date: (dd/mm/yyyy) \n");
scanf("%d %d %d", &dates.day, &dates.month, &dates.year);
for (int i = 1; i < 50; i++){
dates.day += 1;
if (dates.month > 12){
printf("\n-----------------Year Change----------------\n");
dates.month = 1;
dates.year += 1;
if (dates.day > 30){
printf("\n-----------------Month Change--------------\n");
dates.month += 1;
dates.day = 1;
}
}
if (dates.day > 30){
dates.day = 1;
dates.month +=1;
printf("\n-----------------Month Change--------------\n");
if (dates.month > 12){
printf("\n-----------------Year Change---------------\n");
dates.month = 1;
dates.year +=1 ;
}
}
printf("Day is : %d ", dates.day);
printf("Month is : %d ", dates.month);
printf("Year is : %d\n", dates.year);
printf("\n");
}
}