Tuesday, November 6, 2012

Shell Script to Print Fibonacci Series


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((cdo
c=$((a+b))
echo -n "$c "
a=$b
b=$c
done
echo -e "\n"

Output

Enjoy :)

0 comments:

Post a Comment