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)
 returns number of days in a month. More...
 
char is_leap_year (short year)
 return 1 if input year is a leap year otherwise, return 0
 
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)

returns number of days in a month.

Month is identified by an integer -

0 = Jan and 11 = December

For February, adjust for leap year outside the function.

15 {
16  if (month == 1) /* February has 28 days. Adjust leap year in the loop */
17  return 28;
18  else if (month <= 6) /* odd months till July have 30 days - Jan = 0 (even)*/
19  {
20  if (month & 0x01)
21  return 30;
22  else
23  return 31;
24  }
25  else if (month >= 7) /* odd months after July have 31 days*/
26  {
27  if (month & 0x01)
28  return 31;
29  else
30  return 30;
31  }
32  /* should never reach here! */
33  perror("Should never have reached this point!\n");
34  return -1;
35 }