Partilhar via


Featured Small Basic Article - Leap Year Checker

Today I'm featuring this Wiki article:

 

Here is the overview from that article:

For example, let’s say you want to create a program that checks whether a given year’s a leap year or not. It’s a leap year if the year’s evenly divisible by 4. But if it’s evenly divisible by 100, then it also needs to be evenly divisible by 400. The Figure shows you a flowchart of what you’d need to test for.

   

Figure: A flowchart for checking if a given year’s a leap year

Here are three examples of these rules:

  1. Year 2020 is divisible by 4. Since it isn’t evenly divisible by 100, it’s a leap year!
  2. Year 2100 is divisible by 4. Because it’s evenly divisible by 100, you need to check its divisibility by 400. Since it isn’t evenly divisible by 400, it’s not a leap year.
  3. Year 2400 is divisible by 4. Because it’s evenly divisible by 100, you’ll need to check its divisibility by 400. Since it’s evenly divisible by 400, it’s a leap year!

 

For the latest version, you can head to the Wiki article. You can also get the code, output examples, and an explanation of what the code does:

 

Have a Small and Basic New Year!

   - Ninja Ed

Comments

  • Anonymous
    December 29, 2015
    The first draft of this was over on my personal blog: blogs.msdn.com/.../small-basic-example-leap-year-checker.aspx

  • Anonymous
    December 30, 2015
    2016 is a leap year.  Rio Olympic will be held!

  • Anonymous
    January 01, 2016
    Nonki, nice! Hmm, maybe the Leap Year Checker can be useful after all! =^) Thanks!