Storing Fibonacci's sequence in an array?

Hey I am having trouble storing fibonacci's number into an array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>
using namespace std; 


int main()
{
	int Fib[25]; // I initialized the array here
	int fib;
	int fib[1] = 0;// right here is where I run into my problems I want the 
                          first cell to be the number zero and the second to be               
                          a 1. 
	int fib[2] = 1;
	int fib3;

	for (fib[3]=2; fib[3]<25; fib[3]++); // therefore so I can generate my                     numbers here.     
	{
	fib[3] = fib[1] + fib[2];
	fib[1] = fib[2];   
	fib[2] = fib[3];
	}

	for (fib<=0; fib<25; fib++)
		cout<< "Value is " << fib3;


Im just stuck on putting the numbers into the array. Help? please thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "stdafx.h"
#include <iostream>
using namespace std; 

int main()
{
	const int N = 25;

	int Fib[N]; 

	for ( int i =0; i < N; i++ )
	{
		if ( i == 0 ) Fib[i] = 0;
		else if ( i == 1 ) Fib[i] = 1;
		else Fib[i] = Fib[i -1] + Fib[i -2];
	}

	for ( int i = 0; i < N; i++)
		cout<< "Fib[" << i << "] = " << Fib[i];

	return ( 0 );
}
Last edited on
Topic archived. No new replies allowed.