C   34

cal.c

Guest on 15th January 2022 09:24:48 AM

  1. #include<stdio.h>
  2.  
  3. int leap(int);
  4.  
  5. void main()
  6. {
  7.   int d, m, y;
  8.   int ndays, wday;
  9.   char* wdstr;
  10.  
  11.   printf("Enter d, m, y:\n");
  12.   scanf("%d %d %d", &d, &m, &y);
  13.   ndays = daysgoneby(y) + doy(d,m,y);
  14.   wday = dow(ndays);
  15.   switch (wday) {
  16.     case 0:
  17.       wdstr = "Sun";
  18.       break;
  19.     case 1:
  20.       wdstr = "Mon";
  21.       break;
  22.     case 2:
  23.       wdstr = "Tue";
  24.       break;
  25.     case 3:
  26.       wdstr = "Wed";
  27.       break;
  28.     case 4:
  29.       wdstr = "Thu";
  30.       break;
  31.     case 5:
  32.       wdstr = "Fri";
  33.       break;
  34.     case 6:
  35.       wdstr = "Sat";
  36.   }
  37.   printf("Day of the week is: %d (%s).\n", wday, wdstr);
  38. }
  39.  
  40. int leap(int y)
  41. {
  42.   ...
  43. }
  44.  
  45. int dow(int dcount)
  46. {
  47.   int offset = 2; /* 1 Jan 1800 AD is a Wed */
  48.   return ((offset + dcount) % 7);
  49. }
  50.  
  51. int daysgoneby(int y)
  52. {
  53.   ...
  54. }
  55.  
  56. int doy(int d, int m, int y)
  57. {
  58.   ...
  59. }

Raw Paste


Login or Register to edit or fork this paste. It's free.