Day Number
bool is_leap_year(int Y)
{ if (Y%4!=0) return false;
if (Y%100!=0) return true;
if (Y%400!=0) return false;
return true; }
int day_of_year(int Y, int M, int D)
{ int ans=0;
if (M>1) ans=ans+31;
if (M>2)
{ if (is_leap_year(Y))
ans=ans+29;
else
ans=ans+28; }
if (M>3) ans=ans+31;
if (M>4) ans=ans+30;
if (M>5) ans=ans+31;
if (M>6) ans=ans+30;
if (M>7) ans=ans+31;
if (M>8) ans=ans+31;
if (M>9) ans=ans+30;
if (M>10) ans=ans+31;
if (M>11) ans=ans+30;
return ans+D; }
int day_number(int Y, int M, int D)
{ int ans=day_of_year(Y, M, D);
ans=ans+Y*365;
ans=ans+(Y+3)/4;
ans=ans-(Y-1)/100;
ans=ans+(Y-1)/400;
return ans; }
void main(void)
{ const int d20051011 = day_number(2005, 10, 11);
const int d20070520 = day_number(2007, 5, 20);
const int d19860704 = day_number(1986, 7, 4);
printf("11th October 2005 is day number %d\n", d20051011);
printf("20th May 2007 is day number %d\n", d20070520);
printf("so there are %d days between 11th oct 2005 and 20th may 2007\n", d20070520-d20051011);
printf("If you were born on 4th July 1986, you are %d days old\n", d20051011-d19860704); }