Ad
Code
Diff
  • using System;
    
    public class LeapYears
    {
      public static bool IsLeapYear(int year)
      {
        // End of a century must be divisible by 400
        if(year.ToString().EndsWith("00"))
          return year % 400 == 0;// Returns true if year divisible by 400, false otherwise
        else if(year % 4 == 0)
          return true;// Returns true if year divisible by 4 and not end of the century
        else
          return false;
      }
    }
    • using System;
    • public class LeapYears
    • {
    • public static bool IsLeapYear(int year)
    • {
    • // End of a century must be divisible by 400
    • if(year.ToString().EndsWith("00") && year % 400 == 0)
    • return true;
    • // Not the end of a century must be divisible by 4
    • else if(!year.ToString().EndsWith("00") && year % 4 == 0)
    • return true;
    • if(year.ToString().EndsWith("00"))
    • return year % 400 == 0;// Returns true if year divisible by 400, false otherwise
    • else if(year % 4 == 0)
    • return true;// Returns true if year divisible by 4 and not end of the century
    • else
    • return false;
    • }
    • }