-
Notifications
You must be signed in to change notification settings - Fork 0
/
accept date and tell day.c
60 lines (56 loc) · 1.34 KB
/
accept date and tell day.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
//accept date and tell day
//Eg: input date 7 1 2023
//output Saturday
#include<stdio.h>
int isLeapYear(int year){
if(year%4==0){
if(year%100==0 && year%400!=0){
return 0;
}
else{
return 1;
}
}
else{
return 0;
}
}
int main() {
int year;
int refYear=1600, leap=0;
int diff, totalDays,day,month, oddDays;
int lYear[]={3,1,3,2,3,2,3,3,2,3,2,3};
int nYear[]={3,0,3,2,3,2,3,3,2,3,2,3};
char week[7][10]={"sunday",
"monday",
"tuesday",
"wednesday"
,"thursday"
,"friday",
"saturday"};
printf("Enter a date between 1600 to 3000\n");
scanf("%d%d%d",&day,&month,&year);
diff = year - refYear;
while(refYear < year){
if(isLeapYear(refYear))
leap++;
refYear++;
}
totalDays = leap*366 + (diff-leap)*365;
oddDays = totalDays%7;
if(isLeapYear(year)){
for(int i=0;i<month-1;i++){
oddDays+=lYear[i];
}
oddDays+=day%7;
}
else{
for(int i=0;i<month-1;i++){
oddDays+=nYear[i];
}
oddDays+=day%7;
}
printf("Day on %d/%d/%d ",day,month,year);
printf("%s",week[(5+oddDays)%7]);
return 0;
}