/*check given year is leap year or not*/ int isLeapYear(int year, int mon) { int flag = 0; if (year % 100 == 0) { if (year % 400 == 0) { if (mon == 2) { flag = 1; } } } else if (year % 4 == 0) { if (mon == 2) { flag = 1; } } return (flag); }
/* leap year checking*/ if (isLeapYear(year, month)) { days = days + 1; }
/* calculating age in no of days, years and months */ days = days + ct->tm_mday; month = (12 - month) + (ct->tm_mon); year = (ct->tm_year + 1900) - year - 1;
/* checking for leap year feb - 29 days */ if (isLeapYear((ct->tm_year + 1900), (ct->tm_mon + 1))) { if (days >= (DaysInMon[ct->tm_mon] + 1)) { days = days - (DaysInMon[ct->tm_mon] + 1); month = month + 1; } } else if (days >= DaysInMon[ct->tm_mon]) { days = days - (DaysInMon[ct->tm_mon]); month = month + 1; }
if (month >= 12) { year = year + 1; month = month - 12; }
/* print age */ printf("\n## Hey you are %d years %d months and %d days old. ##\n", year, month, days);
ConversionConversion EmoticonEmoticon