Help with shell script to find sum of first n numbers of Fibonacci series | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


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.

Help with shell script to find sum of first n numbers of Fibonacci series

Homework & Coursework Questions


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-28-2010
Kshitija Kshitija is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 28 March 2010, 8:22 AM EDT
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 : "
read MAXTERM
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..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script to find the sum of first n Fibonacci numbers Kshitija Shell Programming and Scripting 1 03-28-2010 07:49 AM
Shell script to generate Fibonacci series using recursion Tapas Bose Shell Programming and Scripting 10 12-09-2009 01:05 PM
problem in fibonacci series janani_kalyan Shell Programming and Scripting 4 02-05-2009 04:25 PM
Fibonacci series nycol Shell Programming and Scripting 16 04-03-2006 01:21 AM



All times are GMT -4. The time now is 06:06 AM.