Fibonacci Series Program in Shell script - Tecnew

Home Ads

Fibonacci Series Program in Shell script

Fibonacci Series Program in Shell script

Share This

 


#!/bin/bash

echo "Enter the number"

read n

a=0;b=1

echo $a

echo $b

#c=$(($a+$b))

while [ `expr $a + $b` -le $n ]            or             while [ `expr $((a+b))` -le $n ]

do

   c=`expr $a + $b`                              or            c=$((a+b))

echo $c

a=$b

b=$c

done



using For loop

#!/bin/bash
# Program for Fibonacci
# Series

# Static input fo N
# N=6
echo enter number:
read N

# First Number of the
# Fibonacci Series
a=0

# Second Number of the
# Fibonacci Series
b=1

echo "The Fibonacci series is : "

for (( i=0; i<N; i++ ))
do
        echo  "$a"
        fn=$((a + b))
        a=$b
        b=$fn
done
# End of for loop





No comments:

Post a Comment