Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
sol1.c File Reference

Problem 19 solution More...

#include <stdio.h>
Include dependency graph for sol1.c:

Functions

char get_month_days (short month)
 Function to get the number of days in a month. More...
 
char is_leap_year (short year)
 Check if input year is a leap year. More...
 
int main (int argc, char **argv)
 Main function.
 

Detailed Description

Problem 19 solution

Author
Krishna Vedala

Function Documentation

◆ get_month_days()

char get_month_days ( short  month)

Function to get the number of days in a month.

Parameters
monthmonth identified by an integer -

0 = Jan and 11 = December

Returns
number of days in given month
Note
For February, adjust for leap year outside the function.
16 {
17  if (month == 1) /* February has 28 days. Adjust leap year in the loop */
18  return 28;
19  else if (month <= 6) /* odd months till July have 30 days - Jan = 0 (even)*/
20  {
21  if (month & 0x01)
22  return 30;
23  else
24  return 31;
25  }
26 
27  // else if (month >= 7) /* odd months after July have 31 days*/
28 
29  if (month & 0x01)
30  return 31;
31 
32  return 30;
33 }

◆ is_leap_year()

char is_leap_year ( short  year)

Check if input year is a leap year.

Parameters
yearyear to check
Returns
1 if input year is a leap year
0 if input year is not a leap year
42 {
43  if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
44  return 1;
45 
46  return 0;
47 }