7 Replies - 12898 Views - Last Post: 15 October 2008 - 04:36 AM Rate Topic: -----

#1 lorelie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-October 08

n series of fibonacci using array

Post icon  Posted 14 October 2008 - 05:35 AM

hi! i am really sorry but i don't have any idea on how i will create code that generates N series of Fibonacci numbers using array :D
Is This A Good Question/Topic? 0
  • +

Replies To: n series of fibonacci using array

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,111
  • Joined: 07-September 06

Re: n series of fibonacci using array

Posted 14 October 2008 - 05:38 AM

Create an array of length N and then fill each index between 0 and N with the number accordingly to the fib sequence.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: n series of fibonacci using array

Posted 14 October 2008 - 05:41 AM

Generally, there are some rules:
[rules][/rules]

But I've got nothing better to do, so...:
#include <iostream>

using namespace std;

// born2c0de's recursive fibonacci method
long fib(unsigned long n) {
    if (n <= 1) {
        return n;
    } else {
        return fib(n-1)+fib(n-2);
    }
}

int main() {
    cout << "How big do you want the sequence to be?\t";
    int input;
    cin >> input;
    int fibonacci[input];
    for (int i = 0; i < input; i++) {
        fibonacci[i] = fib(i);
    }
    for (int i = 0; i < input; i++) {
        cout << fibonacci[i] << " ";
    }
    cin.get();
    return EXIT_SUCCESS;
}

:)
Was This Post Helpful? 1
  • +
  • -

#4 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,559
  • Joined: 25-January 07

Re: n series of fibonacci using array

Posted 14 October 2008 - 05:43 AM

There are snippets available on this topic. Go to the snippets section and see if you can get them.
Was This Post Helpful? 0
  • +
  • -

#5 gothik12  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 207
  • Joined: 10-November 07

Re: n series of fibonacci using array

Posted 14 October 2008 - 06:06 AM

You can also use Google :D
Was This Post Helpful? 0
  • +
  • -

#6 lorelie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-October 08

Re: n series of fibonacci using array

Posted 14 October 2008 - 08:03 AM

hi again,,..

after brain freeze,,
i hope that you'll help me to correct all my errors.
:crazy:
#include<stdio.h>
#define MAX 50
main()
{
int i;
int fib[i];
clrscr();
printf("ENTER TWO NUMBERS:\n\n");
scanf("%d\n %d\n", &fib[0], &fib[1]);

for(i=2;i< MAX-1; i++);
{
fib[i]= fib(i-1)+ fib(i-2);
printf("%d", &fib[i]);
}

getch();
}
Was This Post Helpful? 0
  • +
  • -

#7 lorelie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-October 08

Re: n series of fibonacci using array

Post icon  Posted 14 October 2008 - 08:05 AM

hi again,,..

after brain freeze,,
i hope that you'll help me to correct all my errors.
:crazy:
#include<stdio.h>
#define MAX 50
main()
{
int i;
int fib[i];
clrscr();
printf("ENTER TWO NUMBERS:\n\n");
scanf("%d\n %d\n", &fib[0], &fib[1]);

for(i=2;i< MAX-1; i++);
{
fib[i]= fib(i-1)+  fib(i-2);
printf("%d", &fib[i]);
}

getch();
}

Was This Post Helpful? 0
  • +
  • -

#8 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 117
  • View blog
  • Posts: 1,559
  • Joined: 25-January 07

Re: n series of fibonacci using array

Posted 15 October 2008 - 04:36 AM

You might be expecting something like this...

 
cout << "How many numbers in series? : ";
cin >> count;
cout << fibo1 << " " << fibo2;
for(i=2;i<count;i++)
{
 tmp = fibo1;
 fibo1 = fibo2;
 fibo2 += tmp;
 cout << " " << fibo2;
}



As I wrote this code on the fly, it might have some errors. Just have a close look on it.

I hope this will help you. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1