-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.c
155 lines (151 loc) · 3 KB
/
date.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>
int main()
{
int j,i,days,month,year,no;
long int rday,rmon,ryear,totdays;
printf("Enter the day:");
scanf("%d",&days);
printf("Enter the month:");
scanf("%d",&month);
printf("Enter the year:");
scanf("%d",&year);
printf("Enter the no.of days:");
scanf("%d",&no);
if((year%100==0)&&(year%400==0))
totdays=year*366+days+no;
else if(year%4==0)
totdays=year*366+days+no;
else
totdays=year*365+days+no;
for(j=1;j<=month;j++){
if((j==1)||(j==3)||(j==5)||(j==7)||(j==8)||(j==10)||(j==12))
totdays=totdays+31;
else if((j==4)||(j==6)||(j==9)||(j==11))
totdays=totdays+30;
else{
if(j==2){
if((year%100==0)&&(year%400==0))
totdays=totdays+29;
else if(year%4==0)
totdays=totdays+29;
else
totdays=totdays+28;}
}
}
ryear=totdays/365;
totdays=totdays+1;
for(i=year;i<=ryear;i++){
if((i%100==0)&&(i%400==0)){
totdays--;}
else if(i%4==0){
totdays--;}
else if(i==year){
totdays--;}
}
ryear=totdays/365;
rmon=(totdays%365)/30;
rday=(totdays%365)%30;
if((year%100==0)&&(year%400==0))
{
printf("This is a leap year");
if((days>0 && days<=31)&&(month>0 && month<=12)&&(year>0)){
if(days==31)
{
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\nInvalid input");
}
else
{
if(month==2)
{
if(days<=29)
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\ninvalid input");
}
else{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
}
}
else
printf("\nThis is a invalid input");
}
else if(year%4==0)
{
printf("\nThis is a leap year");
if((days>0 && days<=31)&&(month>0 && month<=12)&&(year>0)){
if(days==31)
{
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\nInvalid input");
}
else{
if(month==2)
{
if(days<=29){
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\ninvalid input");
}
else{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
}
}
else
printf("\nInvalid input");
}
else
{
printf("\nThis is not a leap year");
if((days>0 && days<=31)&&(month>0 && month<=12)&&(year>0)){
if(days==31)
{
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\nInvalid input");
}
else
{
if(month==2)
{
if(days<=28)
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
else
printf("\ninvalid input");
}
else
{
printf("\nValid input");
printf("\n%ld / %ld / %ld",rday,rmon,ryear);
}
}
}
else
printf("\nInvalid input");}
return 0;}