fibonacci

im trying to get this code to run,but every time i do it just closes automatically.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
unsigned long fib(unsigned long);

int main()
{

     for(int counter = 0; counter <= 10;counter ++)
      cout<<"fibonacci{"<<counter<<")"<<fib(counter)<<endl;
      
      return 0;
}

 
unsigned long fib (unsigned long n) 
{
  if ((n == 0) || (n == 1)) 
  return n;
  else 
  return (fib (n-1) + fib (n-2));
}


I know the codes correct,because i copied it out of a textbook.but it still wont show an output. if anyone can help i would appreciate it.
Ah, here's your problem.
http://www.cplusplus.com/forum/articles/7312/

[edit] PS - Look at "The Standard Way"

Hope this helps.
Last edited on
Topic archived. No new replies allowed.