Sunday, 30 October 2016

script to print fibonacci series

echo "Enter n for Fibonacci series: - "
read n
echo "Fibonacci series is: - "
echo "0"
echo "1"
i=0
j=1
cnt=2
while [ $cnt -le $n ]
do
k=`expr $i + $j`
i=$j
j=$k
echo $k
cnt=`expr $cnt + 1`
done

$ ./fibonacci.ksh
Enter n for Fibonacci series: -
10
Fibonacci series is: -
0
1
1
2
3
5
8
13
21
34
55

No comments:

Post a Comment