Created
June 27, 2015 07:04
-
-
Save bharathyes/b9b0f90c71ddc78d02a7 to your computer and use it in GitHub Desktop.
Find the day of a given date -- C program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main () { | |
int d=27, m=6, y=2015, weekday ; | |
printf("Enter date, month and year: "); | |
scanf("%d%d%d",&d,&m,&y); | |
weekday = (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7 ; | |
printf("The day of the week is : %d",weekday); | |
switch(weekday) { | |
case 0: | |
printf(" Sunday.\n"); | |
break; | |
case 1: | |
printf(" Monday.\n"); | |
break; | |
case 2: | |
printf(" Tuesday.\n"); | |
break; | |
case 3: | |
printf(" Wednesday.\n"); | |
break; | |
case 4: | |
printf(" Thursday.\n"); | |
break; | |
case 5: | |
printf(" Friday.\n"); | |
break; | |
case 6: | |
printf(" Saturday.\n"); | |
} | |
return 0; | |
} |
I too face the same problem.
Can you explain it clearly?
For what I determined this could be a variant or simplification of Zeller's congruence but I'm either too dumb or I don't have time at the moment to understand the modifications. It works tho, so that's good.
Also, the line weekday = (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7 ;
could be expanded as
d+=m<3?y--:y-2;
weekday = Math.floor((23*m/9+d+4+y/4-y/100+y/400)%7 );
to port this code to javascript.
thank you, works fine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was unable to understand the logic for the weekday can any one help me please.