C   25

cal-switch.c

Guest on 15th January 2022 09:23:35 AM

  1. #include<stdio.h>
  2.  
  3. int leap(int);
  4.  
  5. void main()
  6. {
  7.   int a, dow;
  8.   char *daystr = "Junk";
  9.  
  10.   scanf("%d", &a);
  11.   dow = dow2017(a);
  12.   switch (dow) {
  13.     case 0:
  14.       daystr = "Sun";
  15.       break;
  16.     case 1:
  17.       daystr = "Mon";
  18.       break;
  19.     case 2:
  20.       daystr = "Tue";
  21.       break;
  22.     case 3:
  23.       daystr = "Wed";
  24.       break;
  25.     case 4:
  26.       daystr = "Thu";
  27.       break;
  28.     case 5:
  29.       daystr = "Fri";
  30.       break;
  31.     case 6:
  32.       daystr = "Sat";
  33.   }
  34.   printf("dow is %d\n", dow);
  35.   printf("The day of the week is %s.\n", daystr);
  36. }
  37.  
  38. int leap(int y)
  39. {
  40.   return (((y % 400) == 0) ||
  41.           (((y % 4) == 0) && ((y % 100) != 0)));
  42. }
  43.  
  44. int dow2017(int dcount)
  45. {
  46.   int offset = 6; /* 1 Jan 2017 is a Sunday */
  47.   return ((offset + dcount) % 7);
  48. }

Raw Paste


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