Leap year using shell script coderinme

Leap year using shell script

as we know that linux and unix os is the best operating system in stability management and security.
so we should learn about script for their shell named as shell scripting, bash program
so what do you think its easy like c.
here it’s a program of leap year using bash
Leap year using shell script

I Solution
#!/bin/bash
(bash copy)
read -p "Enter the year: " year
if [ $year -le 0 ] ; then
year=`date | cut -d " " -f6`
fi
isleap=0
if [ $((year % 4)) -ne 0 ] ; then
isleap=0
elif [ $((year % 400)) -eq 0 ] ; then
isleap=1
elif [ $((year % 100)) -eq 0 ] ; then
isleap=0
else
isleap=1
fi
case $isleap in
0 ) echo "Year $year is Not a leap year";;
1 ) echo "Year $year is a Leap year";;
esac
II Solution

 echo "Enter Year:"
read y

year=$y

if [ $[$year % 400] -eq "0" ]; then
  echo "This is a leap year."
elif [ $[$year % 4] -eq 0 ]; then
        if [ $[$year % 100] -ne 0 ]; then
          echo "This is a leap year, "
        else
          echo "This is not a leap year. "
        fi
else
  echo "This is not a leap year.  February has 28 days."
fi

III Solution

#!/bin/bash
(bash copy)
read -p "Enter the year: " year
isleap=0
if [ $((year % 400)) -eq 0 ] ; then
isleap=1
elif [ $((year % 100)) -eq 0 -o $((year % 4)) -ne 0 ] ; then
isleap=0
else
isleap=1
fi
case $isleap in
0 ) echo "Year $year is Not a leap year";;
1 ) echo "Year $year is a Leap year";;
esac

output

1990
No
2000
Yes
1000
No

for more click lets code

Leave a reply:

Your email address will not be published.