#####################################################
# File Name: sy_4_g
#
# Usage: ./sy_4_g
#
# Author: Suresh Yadagiri
# Date: August 06,2010
#
# Requirements:
# write a c shell script that takes an integer number
# from the keyboard and displays the fibonacci numbners
# equal to the number entered from the keyboard.
# thus if the user enters 7, your script displays the
# first seven fibonacci numbers
#
#
#####################################################
function printusageinfo(){
echo -e "\nUsage: $0
}
function is_integer() {
printf "%d" $1 > /dev/null 2>&1
return $?
}
if [ $# -eq 0 ]
then
echo "At least one argument expected"
printusageinfo
exit 1
fi
if [ $# -gt 1 ]
then
echo "Too many arguments"
printusageinfo
exit 1
fi
if ! is_integer $1;
then
echo "Integer argument expected"
printusageinfo
exit 1
fi
if [ $1 -lt 2 ]
then
echo "invalid arguments.enter greater value"
printusageinfo
exit 1
fi
echo "The first $1 fibonacci numbers are"
counter=2
n1=0
n2=1
echo $n1
echo $n2
until [ $counter -eq $1 ]
do
current=`expr $n1 + $n2`
echo $current
counter=`expr $counter + 1`
n1=$n2
n2=$current
done
exit 0
No comments:
Post a Comment