Académique Documents
Professionnel Documents
Culture Documents
Example:
1. years 1804,1908,2012,2016 are leap years.
2. years 400,800,1200,1600 are leap years.
3. years 1999,2001,2002,2003,1800,600 are not leap years.
Q. How to count odd days?
(I) 1 ordinary year = 365 days = (52 weeks + 1 day). So one ordinary year has 1 odd day.
(II) 1 leap year=366 days=(52 weeks + 2days). So one leap year has 2 odd days.
(III)100 years has 76 ordinary years + 24 leap years = (761+242)odd days = 124 odd days
=(17 weeks + 5 days) = 5 odd days
So,
Number of odd days in 100years = 5 odd days
Number of odd days in 200years = 52 = 3 odd days ( and 1 week)
Number of odd days in 300years = 53 = 1 odd days ( and 2 weeks)
Number of odd days in 400years = 54 + 1 (extra 1 for leap year) = 0 odd days
so, each of years 800,1200,1600, etc has 0 odd days.
How odd days are related to day of week?
ODD DAYS
DAY
Example
Given date 25th Feb 2013
so, odd days = ((odd days till 2013) + (days 1.1.2013 to 25.2.2013))%7
using the above table we can find out which day it is for the corresponding odd-days value
CODE
#include<stdio.h>
#define IS_LEAP_YEAR(Y) (((Y%4 == 0)&&(Y%100 != 0))||(Y% 400 == 0))
#define ODD_DAYS_LEAP_YEAR 2
#define ODD_DAYS_ORDINARY_YEAR 1
int validateInput(int,int,int);
char dayStrings[7][10]={"Sunday","Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday"};
int daysInMonth[12]={31,28,31,30,31, 30,31,31,30,31,30,31};
/*it stores the odd days for 100,200,300 years odd days
*i.e 5,3,1 odd days resp. */
int yearMap[4]={0,5,3,1};
int main()
{
int day,month,year,OrdinaryYears,TOddDays,i,Tdays=0;
int CYears,OddYears,OddDays=0,LeftYears,leapYears;
printf("Enter the Day(1-31):");
scanf("%u",&day);
printf("\nEnter the Month(1-12):");
scanf("%u",&month);
printf("\nEnter the Year:");
scanf("%u",&year);
printf("\n\nInputDate : %02u/%02u/%04u",day,month,year);
/*validate the Inputs*/
if(0 == validateInput(day,month,year))
return 1;
/*Get the completed years*/
CYears = year-1;
/*getting the no of years after the century with 0 odd days*/
OddYears = CYears%400;
/*get the Odd days for complete centuries out of the Oddyears found above.
*i.e 100 years = 5 odd days ,200 years = 3 odd days,etc. */
OddDays += yearMap[OddYears/100];
/*get the years left out (<100)*/
LeftYears = OddYears%100;
/*calculate leap years*/
leapYears = LeftYears/4;
/*calculate ordinary years*/
OrdinaryYears = LeftYears - leapYears;
/*total odd days for left out years*/