#include // The following is necessary if and only if you're using an older // compiler which doesn't recognize type "bool". If used in combination // with a compiler which does recognize "bool", an error will result. // typedef enum { false = 0, true = 1 } bool; // returns true if the year is a leap year bool year_is_leap (int year) { return ((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0)); } int days_in_year (int year) { if (year_is_leap(year)) { return 366; } else { return 365; } } // January = month 1, February = month 2, etc. int days_in_month (int month, int year) { const int days_table [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // look after the special case if ((month == 2) && year_is_leap(year)) { return 29; } return days_table[month - 1]; }