C code to determine the day for a given date

#include <stdio.h>
#include <string.h>
int main()
{
 int dd, yy, q, r, a, b, c, s;
 char mm[15];
 printf("\nenter date: ");
 scanf_s("%d", &dd);
 printf("\nenter year: ");
 scanf_s("%d", &yy);
 printf("\nenter month: ");
 scanf_s("%s", mm);
 q = yy/100;
 r = yy%100;
 switch(q)
 {
  case 16: a = 6; break;
  case 17: a = 4; break;
  case 18: a = 2; break;
  case 19: a = 0; break;
  case 20: a = 6; break;
  default: break;
 }
 b = r/4;
 if(strcmp(mm, "january")==0)
 {
  c = 1;
 }
 if(strcmp(mm, "february")==0)
 {
  if(yy%4 == 0)
  {
   c = 3;
  }
  else
  {
   c = 4;
  }
 }
 if(strcmp(mm, "march") == 0)
 {
  c = 4;
 }
 if(strcmp(mm, "april") == 0)
 {
  c = 0;
 }
 if(strcmp(mm, "may") == 0)
 {
  c = 2;
 }
 if(strcmp(mm, "june") == 0)
 {
  c = 5;
 }
 if(strcmp(mm, "july") == 0)
 {
  c = 0;
 }
 if(strcmp(mm, "august") == 0)
 {
  c = 3;
 }
 if(strcmp(mm, "september") == 0)
 {
  c = 6;
 }
 if(strcmp(mm, "october") == 0)
 {
  c = 1;
 }
 if(strcmp(mm, "november") == 0)
 {
  c = 4;
 }
 if(strcmp(mm, "december") == 0)
 {
  c = 6;
 }
 s = (a + r + b + dd + c) % 7;
 switch(s)
 {
  case 1: printf("\nsunday\n"); break;
  case 2: printf("\nmonday\n"); break;
  case 3: printf("\ntuesday\n"); break;
  case 4: printf("\nwednesday\n"); break;
  case 5: printf("\nthursday\n"); break;
  case 6: printf("\nfriday\n"); break;
  case 0: printf("\nsaturday\n"); break;
  default: break;
 }
 return 0;
}
//Input
//enter date: 23
//enter year: 2008
//enter month: may
//Output
//friday
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s