/* This program reads two dates and prints the number of days between them. Each date is three integers in European order: year, month, day. Try typing 2001 10 27 2002 1 1 to ask for the number of days between 27 October 2001 and 1 January 2002. MJD stands for Modified Julian Date. It increases by 1 every day. It's a standard unit in astronomy. This program does not use struct. It's here for comparison with struct2.c. */ #include int mjd(int dateyear,int datemonth,int dateday) { int y = dateyear; int m = datemonth - 1; int d = dateday - 678882; d += 146097 * (y / 400); y %= 400; if (m >= 2) m -= 2; else { m += 10; --y; } y += (m / 12); m %= 12; if (m < 0) { m += 12; --y; } d += (306 * m + 5) / 10; d += 146097 * (y / 400); y %= 400; if (y < 0) { y += 400; d -= 146097; } d += (y & 3) * 365; y >>= 2; d += 1461 * (y % 25); y /= 25; d += (y & 3) * 36524; return d; } int main(void) { int date1year; int date1month; int date1day; int date2year; int date2month; int date2day; scanf("%d%d%d",&date1year,&date1month,&date1day); scanf("%d%d%d",&date2year,&date2month,&date2day); printf("There are %d days between %d-%02d-%02d and %d-%02d-%02d.\n" ,mjd(date2year,date2month,date2day) - mjd(date1year,date1month,date1day) ,date1year,date1month,date1day ,date2year,date2month,date2day ); return 0; }