05 November 2012

Shell Script to Print Fibonacci Series

Leave a Comment

Q. How do I print fibonacci series in Bash


Ans:

#!/bin/bash
c=0
a=1
b=1
read -p "Enter limit of fibonacci Series:" n
echo -n "$a "
echo -n "$b "
#Fibonacci series logic
while((c<n))
do
c=$((a+b))
echo -n "$c "
a=$b
b=$c
done
echo -e "\n"

Output


shell script to print fibonacci series

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment