Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- a=0
- b=1
- echo -n "Enter the number of terms: "
- read n
- if [ $n -le 0 ]; then
- echo "Error in input"
- exit 0
- fi
- if [ $n -ge 1 ]; then
- echo -n $a " " #-n used for printing on the same line
- fi
- if [ $n -ge 2 ]; then
- echo -n $b " "
- fi
- for(( i=2; i<n; i++ )){ #i=2 because 2 numbers have already been printed
- c=$((a+b)) #equivalent to let c=a+b
- echo -n $c " "
- a=$b
- b=$c
- }
- echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement