Code Scrappers


Calender program- display day of month C program


              #include<stdio.h>
              #include<stdlib.h>

              int FirstMonth(int, int, int);

              int DayOfWeek(int, int, int);

              void main()
              {
                  int d, m, y;

                  printf("\n enter the date ");

                  scanf("%d", &d);

                  printf("\n enter the month ");

                  scanf("%d", &m);

                  printf("\n enter the year ");

                  scanf("%d", &y);

                  DayOfWeek(d, m, y);
              }



              int FirstMonth(int d, int m, int y)
              {
                   int fm, leap;

                   if ((y % 100 == 0) && (y % 400 != 0))
                   {
                      leap = 0;
                   }

                   else if (y % 4 == 0)
                   {
                      leap = 1;
                   }

                   else
                   {
                      leap = 0;
                   }

                   fm = 3 + (2 - leap) * ((m + 2) / (2 * m))
                             + (5 * m + m / 9) / 2;

                   fm = fm % 7;

                   return fm;
              }

              int DayOfWeek(int d, int m, int y)
              {

                  int day;

                  int Year = y % 100;

                  int century = y / 100;

                  printf("\nDate: %d/%d/%d \n", d, m, y);

                  day = 1.25 * Year + FirstMonth(d, m, y) + d - 2 * (century % 4);

                  day = day % 7;

                  switch (day)
                  {
                      case 0:
                        printf("Saturday");
                        break;

                      case 1:
                        printf("Sunday");
                        break;

                      case 2:
                        printf("Monday");
                        break;

                      case 3:
                        printf("Tuesday");
                        break;

                      case 4:
                        printf("Wednesday");
                        break;

                      case 5:
                        printf("Thursday");
                        break;
                      case 6:
                        printf("Friday");
                        break;

                      default:
                        printf("Wrong data");

                      return 0;
                 }
              }

          



Output

    enter the date 06

    enter the month 10

    enter the year 1999

    Date: 6/10/1999

    Wednesday