Programming Olympics / Task: Fibonacci Fun

Programming Olympics

Learn Computer Programming Here ... and maybe represent Ireland?

You are not logged in.

#1 2008-11-05 21:14:17

admin
Administrator
Registered: 2008-11-02
Posts: 56

Task: Fibonacci Fun

The Fibonacci numbers are a sequence of numbers with lots in interesting properties, and have been used in many disciplines, including art, architecture, literature and music. It is also related to the Golden Ratio, a proportion used in Renaissance works by many artists and architects who believed this proportion to be
aesthetically pleasing.

The first number of the sequence is 0, the second number is 1, and each subsequent number is equal to the sum of the previous two numbers in the sequence.
The sequence begins: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

Write a computer program to compute the sum of the first N Fibonacci numbers.

(hint: to check your answer, you can use an interesting property of the sequence. If F(k) is the kth Fibonacci number, then F(k+2)-1 is equal to the sum of the first k Fibonacci numbers)

Offline

 

#2 2008-11-11 18:09:40

davidmc
New member
From: Cork
Registered: 2008-11-11
Posts: 7
Website

Re: Task: Fibonacci Fun

If asked for F(1) should it be 0, F(0) being undefined, or should F(1) be the first 1, leaving F(0) being the 0.

(The latter notation is perhaps more consistent with most references I've seen to the sequence,  but it wasn't clear here)

Offline

 

#3 2008-11-11 19:07:49

Donncha
New member
From: Offaly
Registered: 2008-11-11
Posts: 5

Re: Task: Fibonacci Fun

Just wondering in what range is N, eg 1-100/1000 etc...?


4/3 of people don't understand fractions

Offline

 

#4 2008-11-13 14:40:41

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: Task: Fibonacci Fun

hi guys,

to answer your questions...

David:
  As stated
  >> The first number of the sequence is 0
  and
  >> F(k) is the kth Fibonacci number
  therefore F(1)=0
  F(6)=5, etc

Donncha:
  You are right, a range should have been stated.
  Assume N <= 40
  (I will update the task statement)

Ciarán

Offline

 

#5 2008-11-13 14:49:33

Prometheus
New member
From: Cyberspace
Registered: 2008-11-12
Posts: 8

Re: Task: Fibonacci Fun

So you don't ask the person for the number of fibonacci numbers they want displayed?

Offline

 

#6 2008-11-13 18:18:40

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: Task: Fibonacci Fun

Yes, you will need to input an integer (N) and output the sum of the first N Fibonacci numbers. You do not have to print out all these numbers, merely the sum.

Offline

 

#7 2008-11-21 22:35:08

HappySmileMan
New member
From: Wexford
Registered: 2008-11-21
Posts: 6

Re: Task: Fibonacci Fun

Do I need to worry about whether the user inputs an integer or not and prevent crash, or can I just assume he'll enter an integer and not a character?

EDIT: This could basically apply to all programming challenges here so just in general should we worry about errors like these or assume input will be valid?

Last edited by HappySmileMan (2008-11-21 22:55:15)

Offline

 

#8 2008-11-22 12:23:59

admin
Administrator
Registered: 2008-11-02
Posts: 56

Re: Task: Fibonacci Fun

Thanks for your question.

For all tasks, you may assume the input is valid and will not be out of the stated range.

Offline

 

#9 2010-02-20 21:30:24

NotMyFault
New member
Registered: 2010-01-17
Posts: 9

Re: Task: Fibonacci Fun

Didn't do it the way specified but...

My answer in C++:

#include <iostream>
using namespace std;

int main(void)
{
    unsigned long int fib[41];
    fib[0]=0;
    fib[1]=1;                     //Set-up
    int input=0;
    unsigned long int sum=0;

    cin>>input;

    for(int i=1; i!=input; i++)
    {
        sum = fib[i] + fib[i-1];   //Finding the fibonnacci series
        fib[i+1] = sum;
    }

    cout<<sum;                     //Print the result

}

Last edited by NotMyFault (2010-04-25 13:05:53)

Offline

 

#10 2011-12-26 10:36:02

Fedovup
New member
From: Athens
Registered: 2011-12-21
Posts: 1
Website

Re: Task: Fibonacci Fun

I'm a new member, so I'm just looking around.


essay writers  are skillful and substantiated in their perspective. In case you approach there, you will see how novel their home works are. They often compose on any delicate points and answering to your wishes and benchmarks. You terminations will be cultivating.

Offline

 

#11 2012-01-15 13:34:10

KarenLamb
New member
Registered: 2012-01-15
Posts: 3
Website

Re: Task: Fibonacci Fun

The natural world is loaded with patterns. From leaves on plants to the shape of a nautilus shell, numbers can help us to describe and understand these patterns.
In 1202 A.D., Leonardo Fibonacci discovered a unique mathematical sequence that has importance today. It is one way in which many of nature's most beautiful, strange, and seemingly unrelated objects show similarities.

Offline

 

Board footer

viewtopic

Powered by PunBB
© Copyright 2002–2008 PunBB