The UNIX and Linux Forums Help with shell script to find sum of first n numbers of Fibonacci series
 Member Name Remember Me? Password
 Forums Search Forums Register Forum Rules Man Pages Albums FAQ Members Calendar Search Today's Posts Mark Forums Read

 Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

 Thread Tools Search this Thread Display Modes
#1
03-28-2010
 Registered User Join Date: Mar 2010 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts
Help with shell script to find sum of first n numbers of Fibonacci series

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Shell script to find sum of first n numbers of Fibonacci series

2. Relevant commands, code, scripts, algorithms:

Code:
``` prev=0
next=1

echo \$prev

while(true)
do

echo \$next

#add the two numbers
sum=\$((\$prev+\$next))
#swap
prev=\$next
next=\$sum
sleep 1
done```

3. The attempts at a solution (include all code and scripts):

Code:
```# Shell scrpt to generate Fibonacci series using recursion
export MINIDX=2
Fibonacci ()
{
idx=\$1
if [ "\$idx" -lt "\$MINIDX" ]; then
echo "\$idx"
else
(( --idx ))
term1=\$( Fibonacci \$idx )
(( --idx ))
term2=\$( Fibonacci \$idx )
echo \$(( term1 + term2 ))
fi
}
echo -n "Enter the number of term : "
for (( i=0; i<=\$MAXTERM; i++ ))
do
FIBO=\$(Fibonacci \$i)
echo -n "\$FIBO "
done
echo
exit```

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
D.G Ruparel College(Mumbai University),Mumbai(Maharashtra),India
Professor Puja Tambe and Computer Science

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by DukeNuke2; 03-28-2010 at 08:41 AM..