Advertisement
tampurus

5 Fibonacci Sequence

Jan 22nd, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.33 KB | None | 0 0
  1. echo Enter the fibboncci term
  2. read N
  3. i=3
  4. if [ $N -eq 1 ]
  5. then
  6.     current=0
  7. elif [ $N -eq 2 ]
  8. then    
  9.     current=1
  10. fi
  11.  
  12. below_prev=0
  13. prev=1
  14. current=0
  15.  
  16. while [ $i -le $N ]
  17. do
  18.     current=`expr $below_prev + $prev`
  19.     below_prev=$prev
  20.     prev=$current
  21.     i=`expr $i + 1`
  22. done
  23. echo $N th term of sequence is $current
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement