Days In Month

This algorithm finds the total days in a month according to the input date.



									/*****Please include following header files*****/
// stdbool.h
/***********************************************/

bool IsLeapYear(unsigned int year) {
	return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
}

char GetDaysInMonth(unsigned int year, char month) {
	char daysInMonth;

	if (month == 4 || month == 6 || month == 9 || month == 11)
	{
		daysInMonth = 30;
	}
	else if (month == 2)
	{
		if (IsLeapYear(year))
		{
			daysInMonth = 29;
		}
		else
		{
			daysInMonth = 28;
		}
	}
	else
	{
		daysInMonth = 31;
	}

	return daysInMonth;
}
								


Example

									char value = GetDaysInMonth(2016, 2);
								


Output

									29