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 also 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 - -o $c -eq 0] then echo "$y is leap year" else echo "$y is not a leap year" fi
Input: 2024 Output: "2024 is leap year"
Input: 2018 Output: "2018 is not leap year"
- Introduction to Linux Shell and Shell Scripting
- Bash shell script to find sum of digits
- Bash shell script to swap two numbers
- Bash shell script to find out the largest value from given command line arguments
- Array Basics Shell Scripting | Set 2 (Using Loops)
- Array Basics in Shell Scripting | Set 1
- Basic Operators in Shell Scripting
- How to check if a directory or a file exists in system or not using Shell Scripting?
- Create a password generator using shell scripting
- Calculator Program with Batch Scripting in Windows
- Bash program to check if the Number is a Prime or not
- Bash program to find A to the power B
- Bash program to check if the Number is a Palindrome
- Write a bash script to print a particular line from a file
- Fibonacci Series in Bash
- Useful and time saving bash commands in Linux
- Average of given numbers in Bash
- Sorting an array in Bash using Bubble sort
- Simple Calculator in Bash
- Programs for printing different patterns in Bash
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.