Skip to content

Instantly share code, notes, and snippets.

@jagdish4501
Created April 1, 2021 18:38
Show Gist options
  • Save jagdish4501/254ac8d71889be0343442f931868f656 to your computer and use it in GitHub Desktop.
Save jagdish4501/254ac8d71889be0343442f931868f656 to your computer and use it in GitHub Desktop.
According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.
#include <stdio.h>
int main()
{
int curentYear, baseYear, leapYear, no_leapYear, totalNo_ofDay, year, di;
printf("enter current year=");
scanf("%d", &curentYear);
baseYear = 1900;
year = (curentYear - 1) - baseYear;
leapYear = (year / 4); //because 1900 is not leap year
//for leap year see CH-2[F] (a).c
no_leapYear = year - leapYear;
totalNo_ofDay = (365 * no_leapYear) + (366 * leapYear) + 1; // +1 bec. day ofjan 1 of currentYear
di = (totalNo_ofDay % 7);
if (di == 0)
printf("day is monday");
else if (di == 1)
printf("day is tuesday");
else if (di == 2)
printf("day is wdnessday");
else if (di == 3)
printf("day is trusday");
else if (di == 4)
printf("day is friday");
else if (di == 5)
printf("day is saturday");
else if (di == 6)
printf("day is sunday");
else
printf("some thing went wrong");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment