How do I program the fibonacci serie?

Oct 22, 2011 at 4:00pm
I'm a beginner c++ programmer, and I need to make a code that show the Fibonacci serie. I have been trying some examples but I can not do anything.
I declared some variables like n1, n2, n3, sum, counter, and some others structures. Help please.
Oct 22, 2011 at 4:09pm
Have you tried googling? Fibonacci sequence is one of the most common example programs.
Oct 22, 2011 at 4:36pm
The program below creates and puts in an array the Fibonacci serie. The program can help you but you have to understand his logical part. This is all I got in my PC right now. I can implement it but I am very busy right now. If you know to work with vectors, the program is very easy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
using namespace std;
int main()
{
int v[100][100],i,n,j;
long p,a,f;
cout << "Columns / Rands :"; cin >> n;
f=1;
a=0;
p=0;
for(i=0; i<n; i++)
    for(j=0; j<n; j++)
    {
    v[i][j] = f;
    p=a;
    a=f;
    f=a+p;
    }
 
for(i=0; i<n; i++)
  {
   cout << endl;
   for(j=0; j<n; j++)
       {
         cout << v[i][j];
       }
   }
}




Last edited on Oct 22, 2011 at 4:36pm
Oct 23, 2011 at 2:15pm
Thanks a lot for the code as you may know I am very new at this, you've been very helpful.
Topic archived. No new replies allowed.