Monday 9 July 2012

Write a shell script to find whether a given year(4 digits)is leap year or not.




echo "Enter the year in 4 digits: "
read num
if [ $num -ge 1000 -a $num -le 9999 ]
then
if [ `expr $num % 4` -eq 0 ]
then
echo "The year $num is a Leap year"
else
echo "The year $num is not a Leap year"
fi
else
echo "Invalid year format"
fi

--------------------------------------------------------------------------------------------------------------
                OUTPUT
Enter the year in 4 digits:
2000
The year 2000 is a Leap year

0 comments:

Post a Comment