Thursday, June 21, 2018

Write a shell script to find first n Fibonacci numbers like: 0 1, 1, 2, 3, 5, 13,... - OS

echo "How many number of terms to be generated ?"
read n
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done

No comments:

Post a Comment