Showing posts with label Leap year. Show all posts
Showing posts with label Leap year. Show all posts

Thursday, March 12, 2015

Leap year

Algorithm
Step 1 : Start
Step 2 : Read the value of year
Step 3 : If year divisible by 400 then
Print "Leap year"
Step 3.1 : else if year divisible by 4 and not divisible by 100 then
Print "Leap year"
Step 3.2 : else
Print "Not a leap year"
Step 4 : Stop

Program (leap.sh)
# Leap year
echo -n "Enter a year : "
read year
rem1=`expr $year % 4`
rem2=`expr $year % 100`
rem3=`expr $year % 400`
if [ $rem3 -eq 0 ]
then
echo "$year is a Leap Year"
elif [ $rem2 -ne 0 -a $rem1 -eq 0 ]

Saturday, January 11, 2014

PROGRAM TO DETERMINE WHETHER THE GIVEN YEAR IS LEAP YEAR

echo enter a year
read n
if test `expr $n % 4` -eq 0
then
echo leap year
else
echo not a leap year
fi

~
~
OUTPUT

[staff@linuxserver staff]$ sh leap
enter a year
2008
leap year
[staff@linuxserver staff]$ sh leap
enter a year
2009
not a leap year



 PROGRAM TO GENERATE THE FINOCCI SERIES

echo "enter the number"
read n
echo "The result is"
c=0
a=0
b=1
echo "$a"
echo "$b"
n=`expr $n - 2`
while test $n -ne 0
do
c=`expr $a + $b`
echo "$c"
a=$b
b=$c
n=`expr $n - 1`
done
~



OUTPUT:


[eceb33@linuxserver eceb33]$ sh fiboo
enter the number
8
The result is
0
1
1
2
3
5
8
13