Skip to content

Instantly share code, notes, and snippets.

@a2gs
Last active March 4, 2019 02:43
Show Gist options
  • Save a2gs/ff2aa79b46f0328f7d732d7f99088cb7 to your computer and use it in GitHub Desktop.
Save a2gs/ff2aa79b46f0328f7d732d7f99088cb7 to your computer and use it in GitHub Desktop.
Leap year calculation
/*
* 1 - is
* 0 - is not
*/
int a2gs_AddSubDate_isLeapYear(int year)
{
if(year % 4 == 0){
if(year % 100 == 0){
if(year % 400 == 0)
return(1);
return(0);
}
return(1);
}
return(0);
}
@a2gs
Copy link
Author

a2gs commented Mar 4, 2019

A better solution:

int a2gs_AddSubDate_isLeapYear(int year)
{
	int m4, m100, m400;

	m4 = year % 4;
	m100 = year % 100;
	m400 = year % 400;

	if(((m4 == 0) && (m100 == 0) && (m400 == 0)) || ((m4 == 0) && (m100 != 0)))
		return(1);

	return(0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment