The Student Room Group

k-shell anyone?

Need some help on this script.. I've managed to get a fibianci script working but I want to find the sum sum of all the even-value terms which don't exceed 4 million


#!/bin/sh

# Shell scrpt to generate Fibonacci series using recursion

export MINIDX=2

fibonnacci()
{
case $n in
0) echo 0; return;;
1) echo 0 1; return;;
*) echo -n 0 1
a=0; b=1; c=2;
while [ $c -le $n ]
do
t=$(( a + b ))
echo -n " $t"
a=$b; b=$t;
c=$(( c + 1 ))
done
echo
return;;
esac
}
#
n=${1:-10}
if [ ! `expr $n + 1 2> /dev/null` ] ; then
echo "Value of the arguments < $n > IS NOT an integer!"
exit 1
fi
echo "Fibonnacci series for value $n is:"

while
fibonnacci $n
exit 0



thinking of something like,

while n < 4000000
sum +t

Quick Reply

Latest

Trending

Trending