C Program to know Day by giving Date Input

  1. #include < stdio.h >   
  2. #include < conio.h >  
  3.     void main() {  
  4.         int a, b, c, d, e, f, g, h;  
  5.         clrscr();  
  6.         printf("Enter the date like(1 to 31):\t");  
  7.         scanf("%d", & d);  
  8.         printf("\nEnter the month like(1 to 12):\t");  
  9.         scanf("%d", & a);  
  10.         printf("\nEnter the year like(1996):\t");  
  11.         scanf("%d", & b);  
  12.         printf("\nYour entered date is:%d-%d-%d", d, a, b);  
  13.         printf("\n");  
  14.         c = (14 - a) / 12;  
  15.         e = b + 4800 - c;  
  16.         f = a + 12 * c - 3;  
  17.         g = (d + ((153 * f + 2) / 5) + 365 * e + (e / 4) - (e / 100) + (e / 400) - 32045) % 7;  
  18.         h = g - 2;  
  19.         //printf("%d",h);  
  20.         printf("\nDay on this date:\t");  
  21.         switch (h) {  
  22.             case 1:  
  23.                 printf("MONDAY");  
  24.                 break;  
  25.             case 2:  
  26.                 printf("TUESDAY");  
  27.                 break;  
  28.             case 3:  
  29.                 printf("WEDNESDAY");  
  30.                 break;  
  31.             case 4:  
  32.                 printf("THURSDAY");  
  33.                 break;  
  34.             case -2:  
  35.                 printf("FRIDAY");  
  36.                 break;  
  37.             case -1:  
  38.                 printf("SATURDAY");  
  39.                 break;  
  40.             case 0:  
  41.                 printf("SUNDAY");  
  42.                 break;  
  43.             default:  
  44.                 printf("\nInvalid application error..");  
  45.         }  
  46.         getch();  
  47.     }