Program to Find Fibonacci Series using Shell Script

This is the bash code for Fibonacci Series upto a number n which will be inserted by user.

Code:

clear
echo "Program to Find Fibonacci Series"
  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

Output:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.