Shell script to print Fibonacci series with Algorithm

  • Problem Statement:

Write a shell script to print Fibonacci series

  • Algorithm:

 

Here we are giving only the upper limit of the wanted Fibonacci series, by the program default the lower limit is zero.

INPUT: n [upper limit]

OUTPUT: Fibonacci series [up to n]

Step 01:           Start
Step 02:           read n
Step 03:           a ß 0
Step 04:           b ß 1
Step 05:           display “The fibonacci Series is”
Step 06:           for i ß 0
                        repeat step 7 to 10 while i<n
Step 07:           display a
Step 08:           c ß a+b
Step 09:           a ß b
Step 10:           b ß c
Step 11:           Stop

Source Code

# Print Fibonacci series
read n
a=0
b=1

echo "The fibonacci Series is "

for ((i=0;i<n;i++))
do
	echo -ne "$a\t"
	c=$((a + b))
	a=$b
	b=$c
done

Leave a Comment

Your email address will not be published. Required fields are marked *