Skip to content

Instantly share code, notes, and snippets.

@chris-pws
Created April 1, 2021 07:08
Show Gist options
  • Save chris-pws/68fa60d5eae789b765cca57fb75bfd73 to your computer and use it in GitHub Desktop.
Save chris-pws/68fa60d5eae789b765cca57fb75bfd73 to your computer and use it in GitHub Desktop.
Leap year
int numDays(int month, int year)
{
if ( (month == 1 ) || (month == 3 ) || (month == 5 ) || (month == 7 ) || (month == 8 ) ||
(month == 10 ) || (month == 12 ) )
{
return 31;
}
if (month == 2)
{
if ( year % 4 != 0 )
{
return 28;
}
else if ( year % 100 != 0 )
{
return 29;
}
else if ( year % 400 != 0 )
{
return 28;
}
else
{
return 29;
}
}
return 30;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment