title: How to find leap year programmatically in C
body: <p>I wrote a program in C to find whether the entered year is a leap year or not. But unfortunately its not working well. It says a year is leap and the preceding year is not leap.</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  int yearr(int year);
  
  void main(void) {
      int year;
      printf("Enter a year:");
      scanf("%d", &amp;year);
      if (!yearr(year)) {
          printf("It is a leap year.");
      } else {
          printf("It is not a leap year");
      }
  
      getch();
  }
  
  int yearr(int year) {
      if ((year % 4 == 0) &amp;&amp; (year / 4 != 0))
          return 1;
      else
          return 0;
  }
  </code></pre>
  
  <p>After reading the comments I edited my code as:</p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  int yearr(int year);
  
  void main(void) {
      int year;
      printf("Enter a year:");
      scanf("%d", &amp;year);
      if (!yearr(year)) {
          printf("It is a leap year.");
      } else {
          printf("It is not a leap year");
      }
  
      getch();
  }
  
  int yearr(int year) {
      if (year % 4 == 0) {
          if (year % 400 == 0)
              return 1;
          if (year % 100 == 0)
              return 0; 
      } else
          return 0;
  }
  </code></pre>