Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,634 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,223 people online right now. Registration is fast and FREE... Join Now!




n series of fibonacci using array

 
Reply to this topicStart new topic

n series of fibonacci using array

lorelie
post 14 Oct, 2008 - 04:35 AM
Post #1


New D.I.C Head

*
Joined: 14 Oct, 2008
Posts: 6

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 biggrin.gif
User is offlineProfile CardPM

Go to the top of the page


BetaWar
post 14 Oct, 2008 - 04:38 AM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,976



Thanked 77 times

Dream Kudos: 1175
My Contributions


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.gif

Thanks.
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 14 Oct, 2008 - 04:41 AM
Post #3


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,377



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


Generally, there are some rules:
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.

Please post like this:

Thank you for helping us helping you.

But I've got nothing better to do, so...:
cpp
#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;
}

smile.gif
User is offlineProfile CardPM

Go to the top of the page

AmitTheInfinity
post 14 Oct, 2008 - 04:43 AM
Post #4


C Surfing ∞

Group Icon
Joined: 25 Jan, 2007
Posts: 1,012



Thanked 34 times

Dream Kudos: 125
My Contributions


There are snippets available on this topic. Go to the snippets section and see if you can get them.
User is online!Profile CardPM

Go to the top of the page

gothik12
post 14 Oct, 2008 - 05:06 AM
Post #5


D.I.C Head

Group Icon
Joined: 10 Nov, 2007
Posts: 100



Thanked 2 times

Dream Kudos: 25
My Contributions


You can also use Google biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

lorelie
post 14 Oct, 2008 - 07:03 AM
Post #6


New D.I.C Head

*
Joined: 14 Oct, 2008
Posts: 6

hi again,,..

after brain freeze,,
i hope that you'll help me to correct all my errors.
crazy.gif
#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();
}

User is offlineProfile CardPM

Go to the top of the page

lorelie
post 14 Oct, 2008 - 07:05 AM
Post #7


New D.I.C Head

*
Joined: 14 Oct, 2008
Posts: 6

hi again,,..

after brain freeze,,
i hope that you'll help me to correct all my errors.
crazy.gif
CODE
#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();
}
User is offlineProfile CardPM

Go to the top of the page

AmitTheInfinity
post 15 Oct, 2008 - 03:36 AM
Post #8


C Surfing ∞

Group Icon
Joined: 25 Jan, 2007
Posts: 1,012



Thanked 34 times

Dream Kudos: 125
My Contributions


You might be expecting something like this...

CODE

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. smile.gif
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 05:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month