I have been given this test question:
In the output, in the following lines, write the next terms of the Fibonacci sequence from the first to the nth term inclusive. We assume that the first and second terms of the Fibonnaci sequence are 0 and 1.
I copied shell code to generate the Fibonacci sequence (from here), I just need to have the condition 1<=n<=50
and I can't understand how to add this after the while loop:
function fib
{
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done
}
r=`fib $n`
echo "$r"
{}
and is above your question editor)! – Marcus Müller Apr 08 '23 at 13:39n > 50
? Should it exit? Print an error? Return the result for until the largest value ofn
which is still< 50
? And Where isn
defined? – terdon Apr 08 '23 at 13:56