Open In App
Related Articles

Leap Year Program with Bash Shell Scripting in Windows

Like Article
Save Article
Report issue

Accurately the Earth has 365.24 days per year, to correct the approximation and keep track of the Solar Calendar the idea of leap year has been introduced to Gregorian Calendar. A leap year comes once every four years. In contrast, it has 366 days with regular years, having 365 days.

Mathematical approach to check:

  • Every year is a Leap year if it is evenly divided by four.
  • Every year evenly divided by 100 BUT not 400 is not a leap year.
  • Every year evenly divided by 400 is a leap year.

Use the following shell script for the same.

echo -n "Enter year (YYYY): "
read y
a = 'expr $y%4'
b = 'expr $y%100'
c = 'expr $y%400'
if [$a -eq 0 -a $b -ne 0 -o $c -eq 0]
echo "$y is leap year"
echo "$y is not a leap year"


Unix Script to check leap year


Input: 2024
Output: "2024 is leap year"

Time complexity: O(1) because it is doing constant operations

Auxiliary space: O(1)

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 02 Mar, 2023
Like Article
Save Article
Similar Reads