Advertisement
Shailrshah

Day of the Week by Zeller's Congruence

May 26th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. //h= [ q + floor(13*(m-1)/5) + floor(k/4) + floor(j/4) + 5*j ] % 7
  2. #include <stdio.h>
  3. #include <math.h>
  4. int main()
  5. {
  6.   int h,q,m,k,j,day,month,year;
  7.   printf("Enter the date (dd/mm/yyyy)\n");
  8.   scanf("%i/%i/%i",&day,&month,&year);
  9.   if(month < 3)
  10.   {
  11.     month += 12;
  12.     year--;
  13.   }
  14.   q = day;
  15.   m = month;
  16.   k = year % 100;
  17.   j = year / 100;
  18.   h = q + floor(13*(m+1)/5) + k + floor(k/4) +  floor(j/4) + 5 * j;
  19.   h = h % 7;
  20.   switch(h)
  21.   {
  22.     case 0 : printf("Saturday.\n"); break;
  23.     case 1 : printf("Sunday.\n"); break;
  24.     case 2 : printf("Monday. \n"); break;
  25.     case 3 : printf("Tuesday. \n"); break;
  26.     case 4 : printf("Wednesday. \n"); break;
  27.     case 5 : printf("Thurday. \n"); break;
  28.     case 6 : printf("Friday. \n"); break;
  29.   }
  30.   fflush(stdin);
  31.   getchar();
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement