Day Of Year

This algorithm finds the number of current day in a year 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));
}

int GetDayOfYear(unsigned int year, char month, char day) {
	unsigned short days[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };

	if (IsLeapYear(year) && month >= 2)
		return days[month - 1] + day + 1;

	return days[month - 1] + day;
}
								


Example

									int value = GetDayOfYear(2015, 8, 7);
								


Output

									219