title: Last day of a given month
body: <p>I've got an issue which I can't find a solution. Or at least a "good" one. 
  I want to find the last day of the month given a month and a year in C.</p>
  
  <p>For example : </p>
  
  <pre><code>last_day(10, 2017) &gt; 31
  last_day(02, 2017) &gt; 28
  last_day(02, 2016) &gt; 29
  last_day(01, 2017) &gt; 31
  last_day(12, 2010) &gt; 31
  </code></pre>
  
  <p>last_day(X, Y) > X is the month, Y the year</p>
  
  <p>Here is my idea: Get the day on the month X + 1, of year Y. Remove 1 day from this date. </p>
  
  <p>I would like to know if there is a better solution than that, since that will a make "lot" of operation for a "simple" thing.</p>
  
  <p>Thanks.</p>
  
  <p>Edit : <a href="https://ideone.com/sIISO1" rel="nofollow noreferrer">https://ideone.com/sIISO1</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
  
  int main(void) {
      struct tm tm;
      char out[256];
  
      memset(&amp;tm, 0, sizeof(struct tm));
  
      tm.tm_mon = 1;
      tm.tm_mday = 0;
  
      strftime(out, 256, "%d-%m-%Y", &amp;tm);
  
      printf("%s", out);
  
      return 0;
  }
  </code></pre>
  
  <p>I've tested by using struct tm, and day = 0, in order to get the previous day but did not work</p>