Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Fibonacci sequence practice problem

Here are some projects of actual programs you can practice making.

Fibonacci sequence practice problem

Postby noobgrammer on Fri Oct 02, 2009 12:03 pm

Ok I keep saying I'm going to post some practice problems and so here we go


For this practice problem even if it's simple do them anyway you might surprise yourself
this will be a recursion practice problem


make the Fibonacci sequence using recursion (1+1 =2, 2+1 = 3, 3+2 = 5, 5+3 = 8, 8+5 = 13) you get the idea. do it however you want you could ask a user how many numbers you want in the sequence or just give a set number or make your own starting sequence do a countdown sequence it doesn't matter so long as you can get the recursion to do what you want it to do. If you don't know what recursion is it is where you keep calling the same function over and over. So if you don't have a way to stop it, it would cause a stack overflow error(a infinite loop)
good luck and please post your results I would like to see what ideas you all have in mind. I will post mine after a few are posted to help you use your creativity.


After doing it with recursion see what other ways you can make the Fibonacci sequence work
post them as well


Good luck

EDIT: Ok I put a little example of what recursion looks like. I'm sure somebody better could make it even tighter looking but hey I'm a noob still too


Code: Select all
#include <iostream>

int recursion(int countdown);

int main()
{
   int counter = 10;
   recursion(counter);
   std::cout<< "Blast off\n";
   
}

int recursion(int countdown)
{
   
   if (countdown == 0)
   {
      return 1;
   }
   std::cout<< countdown << "\n\n\n";
   return recursion(countdown - 1);
}


you may notice I don't put in anything to keep it from diapering after it's run. I use visual studios so I just always run my programs with (ctrl + F5) does the same thing as if you have system pause
Last edited by noobgrammer on Sat Oct 03, 2009 8:11 am, edited 1 time in total.
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Fibonacci sequence practice problem

Postby chedder on Fri Oct 02, 2009 12:46 pm

Here is my generator:

Code: Select all

#include "stdafx.h"

#include <iostream>

using namespace std;


int main()
{
   int number;


   int first = 1;
   int second = 1;
   int third;


   cout << "Hello and welcome to the Fibonacci sequence generator\n";
   cout << "Please enter the number of numbers you would like in the sequence... ";
   
   cin >> number;

   cout << "Thank you, here is your sequence:\n\n";

   while (number)
   {

      third = (first + second);
      cout << third << endl;

      first = second;
      second = third;

   
   number--;
   }

   
   char f;
   cin >> f;
   return 0;
}


Thanks for putting up this project, has made me think back to loops. And I will most likely learn more when I see other (properly better) codes!
chedder
 
Posts: 19
Joined: Sat Sep 19, 2009 7:07 am

Re: Fibonacci sequence practice problem

Postby Ruddie on Fri Oct 02, 2009 1:07 pm

What do you think of this? I love the first line! =p

Code: Select all
#include <iostream>
#include <windows.h>

using namespace std;

char runagain = 'Y';
int loopamount = 0 ;
int runs = 0 ;

int main()
{
   while ( runagain != 'N'){

   cout<<"Welcome ";
      Sleep(200);
   cout<<"to ";
      Sleep(200);
   cout<<"the ";
      Sleep(200);
   cout<<"Fibonacci " ;
      Sleep(200);
   cout<<"sequence " ;
      Sleep(200);
   cout<<"generator.\n\n";
      Sleep(200);
   Sleep(1000);

   int a = 1 ;
   int b = 1 ;
   int c ;
   
   cout<<"How many times would you like to run the Fibonacci loop?\n";
   cin>>loopamount;
   
   while ( runs < loopamount )
   {
      c = a + b ;
         
      cout<< a <<" + "<< b <<" = "<< c <<endl ;
      
      a = b ;
      b = c ;
      runs++ ;   
      
   }
   Sleep(1500);
   cout<<"Loop completed, do you wish to run the loop again? (Y/N)\n";
   cin>>runagain ;
   if ( runagain != 'N'){
      system("CLS");
   }
   }

   return 0 ;
}
Last edited by Ruddie on Fri Oct 02, 2009 1:43 pm, edited 1 time in total.
Cheese tastes good!
User avatar
Ruddie
 
Posts: 36
Joined: Tue Sep 22, 2009 3:56 pm
Location: Netherlands

Re: Fibonacci sequence practice problem

Postby chedder on Fri Oct 02, 2009 1:40 pm

Wow Ruddie, liking the code! Haven't used sleep before, it the time in the brackets ms?
chedder
 
Posts: 19
Joined: Sat Sep 19, 2009 7:07 am

Re: Fibonacci sequence practice problem

Postby Ruddie on Fri Oct 02, 2009 1:44 pm

epic color + text scroll thingy!! w0h

Code: Select all
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

char runagain = 'Y';
int loopamount = 0 ;
int runs = 0 ;

int main()
{
   system("Color 1B");
   while ( runagain != 'N'){

      cout<<"W";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"l";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"m";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"t";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"t";
      Sleep(100);
      cout<<"h";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);
      
      cout<<"F";
      Sleep(100);
      cout<<"i";
      Sleep(100);
      cout<<"b";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"a";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"i";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"s";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"q";
      Sleep(100);
      cout<<"u";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"g";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"r";
      Sleep(100);
      cout<<"a";
      Sleep(100);
      cout<<"t";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"r";
      Sleep(100);
      cout<<".\n\n";
      Sleep(100);
   
   Sleep(1000);

   int a = 1 ;
   int b = 1 ;
   int c ;
   
   cout<<"How many times would you like to run the Fibonacci loop?\n";
   cin>>loopamount;
   cout<<endl;
   
   while ( runs < loopamount )
   {
      c = a + b ;      

      cout<< a <<" + "<< b <<" = "<< c <<endl ;

      a = b ;
      b = c ;
      runs++ ;   
      
   }
   Sleep(1500);
   cout<<"\nLoop completed, do you wish to run the loop again? (Y/N)\n";
   cin>>runagain ;
   if ( runagain != 'N'){
      system("CLS");
   }
   }

   
   return 0 ;
}
Cheese tastes good!
User avatar
Ruddie
 
Posts: 36
Joined: Tue Sep 22, 2009 3:56 pm
Location: Netherlands

Re: Fibonacci sequence practice problem

Postby Ruddie on Fri Oct 02, 2009 2:05 pm

Ruddie wrote:epic color + text scroll thingy!! w0h

Code: Select all
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

char runagain = 'Y';
int loopamount = 0 ;
int runs = 0 ;

int main()
{
   system("Color 1B");
   while ( runagain != 'N'){

      cout<<"W";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"l";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"m";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"t";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"t";
      Sleep(100);
      cout<<"h";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);
      
      cout<<"F";
      Sleep(100);
      cout<<"i";
      Sleep(100);
      cout<<"b";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"a";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"i";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"s";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"q";
      Sleep(100);
      cout<<"u";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"c";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<" ";
      Sleep(100);

      cout<<"g";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"n";
      Sleep(100);
      cout<<"e";
      Sleep(100);
      cout<<"r";
      Sleep(100);
      cout<<"a";
      Sleep(100);
      cout<<"t";
      Sleep(100);
      cout<<"o";
      Sleep(100);
      cout<<"r";
      Sleep(100);
      cout<<".\n\n";
      Sleep(100);
   
   Sleep(1000);

   int a = 1 ;
   int b = 1 ;
   int c ;
   
   cout<<"How many times would you like to run the Fibonacci loop?\n";
   cin>>loopamount;
   cout<<endl;
   
   while ( runs < loopamount )
   {
      c = a + b ;      

      cout<< a <<" + "<< b <<" = "<< c <<endl ;

      a = b ;
      b = c ;
      runs++ ;   
      
   }
   Sleep(1500);
   cout<<"\nLoop completed, do you wish to run the loop again? (Y/N)\n";
   cin>>runagain ;
   if ( runagain != 'N'){
      system("CLS");
   }
   }

   
   return 0 ;
}



got a better one now, changed the long rubbish code into an array!

Code: Select all
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

char runagain = 'Y';
int loopamount = 0 ;
int runs = 0 ;
int run = 0;

char title[45] = { 'W','e','l','c','o','m','e',' ','t','o',' ','t','h','e',' ','F','i','b','o','n','a','c','c','i',' ','s','e','q','u','e','n','c','e',' ','g','e','n','e','r','a','t','o','r','.'};

int main()
{
   system("Color 1B");

   

   while ( runagain != 'N' || runagain != 'n' ){

   while ( run < 45 )
   {
      cout<<title[run];
      run++;
      Sleep(100);
   }

   int a = 1 ;
   int b = 1 ;
   int c ;
   
   cout<<"\nHow many times would you like to run the Fibonacci loop?\n\n";
   cin>>loopamount;
   cout<<endl;
   
   while ( runs < loopamount )
   {
      c = a + b ;      

      cout<< a <<" + "<< b <<" = "<< c <<endl ;

      a = b ;
      b = c ;
      runs++ ;   
      
   }
   Sleep(1500);
   cout<<"\nLoop completed, do you wish to run the loop again? (Y/N)\n";
   cin>>runagain ;
   if ( runagain != 'N'){
      system("CLS");
   }
   }

   
   return 0 ;
}
Cheese tastes good!
User avatar
Ruddie
 
Posts: 36
Joined: Tue Sep 22, 2009 3:56 pm
Location: Netherlands

Re: Fibonacci sequence practice problem

Postby noobgrammer on Fri Oct 02, 2009 4:50 pm

I am happy to see that my project was looked at and already replied to

Your guys work and effort were great
Chedder I liked the idea you used in your while loop took me a second to figure out how that worked
good work there

Ruddie you put the creativity into your project that's one of the things I was hoping to see that's what makes it all fun

I'll give you a couple nitpickers to your project really just one bug I saw maybe two

You had a bug with your variable

Code: Select all
int runs = 0 ;


It doesn't reset to 0 so if you put a smaller number than the one before it just loops back and eventually infinitely loops. it's the same with run but that one makes sense not to repeats every time and won't crash the program.
just add
Code: Select all
runs = 0

at the top of the loop

also a note your array doesn't need the
Code: Select all
char title[45]   // no need for 45

char title[]

45 put in because it already knows about it because you are initializing it from the start.

I don't know why but your


Code: Select all
while ( runagain != 'N' || runagain != 'n' )


just was not working with the or statement I think something to do using the not operator
I just did

Code: Select all
while ( runagain == 'Y' )


and now it works for me

you also put in 2 C headers I'm not sure why but they are not necessary

Code: Select all
#include <stdlib.h>
#include <stdio.h>



great work both of you for trying


On a side note these are being done with normal loops which is great but the real challenge is using recursion. Where a function keeps calling itself. and yes on a large scale recursion would be horrible to use but in some cases it is faster to use. I only say that because I've read it many time so I can't tell you from personal experience but from experienced programmers. So I emphasize on trying recursion practice I'll post mine in a day or so if you're confused on how exactly to do it.

I plan on posting a much more complicated one but I need to be able to do it myself first to make sure I'm not posting bunk projects.

So keep up the good work and efforts
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Fibonacci sequence practice problem

Postby noobgrammer on Wed Oct 07, 2009 5:00 pm

Ok I decided not to post my code but a different one so as not to give it away on how to do it((Yes you have to think on this one) . I posted the Gauss recursion. If you're not familiar with him he was the kid that was stuck in a corner at school and for punishment he was suppose to add 1+2+3...100 and come back with the answer. Well he came back in a minute or so with the answer. (I've heard multiple stories but that one made the most sense) He used this formula (n+1)(n/2) in layman's terms that would be (n * (n + 1))/2 so say you put in 3 for n that would be (3 *(3+1))/2 . to check it 1+2+3 =6. So run this program try it in debugger step by step to see if it makes sense to you .

I also tossed something that might be new to you . The ? : are if and else. Helps to keep the code small.

condition? condition passed : condition failed


Code: Select all
#include <iostream>

int gauss(int n);

int main()
{
   int num;
   std::cout<< "Enter a number\n";
   std::cin>> num;
   std::cout<< gauss(num)<<std::endl;
   
}

int gauss(int n)
{
   int x ;
   
   n == 0 ? x = 0: x = n + gauss(n-1);
   
   return x;
}
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Fibonacci sequence practice problem

Postby programmattic on Tue Oct 27, 2009 6:23 pm

Here's my go:

Code: Select all
#include "stdafx.h"
#include <iostream>

using namespace std;

int main(){
   
   int loop;
   unsigned int num1 = 1;
   unsigned int num2 = 1;
   cout << "How many times do you want it to loop?" << endl;
   cin >> loop;

   cout << num1 << endl;

   for (int i = 1; i < loop; i++) {
      cout << num2 << endl;
      num2 += num1;
      num1 = num2 - num1;
   }

   system("pause");
   return 0;
}
programmattic
 
Posts: 8
Joined: Sun Oct 18, 2009 5:02 pm

Re: Fibonacci sequence practice problem

Postby noobgrammer on Tue Oct 27, 2009 9:34 pm

not bad the way you have it set up is not to far in the thinking of using recursion
I will give you a few tips

1.

Code: Select all
using standard std;


I'm sure you have heard not to use it, you will build a bad habit if you always use it. it is easier to teach to use that because there is less to explains so you are told to use it.
it has the scope rule so if you stuck it inside of main your functions would not know about it.
the two alternatives are

Code: Select all
using std:: //then stick what you are using like if you had a lot of couts then you would put this at the top of your functions

using std::cout;

or just every time just put std:: before everyone that needs it.


the second is you are using VS so get rid of the system pause and just run it with ctrl+F5 and you will not need the system pause.

these are just suggestions to help you, what I just mentioned are just bad habits so I say them just to help break them
otherwise your program looks good keep it up :D
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Fibonacci sequence practice problem

Postby glinka57 on Wed Oct 28, 2009 10:36 pm

Here's my version. had to do a bit of research on the sequence, very interesting about the golden ratio.

Code: Select all
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;


void gotoxy ( short x, short y )
{
  COORD coord = {x, y};
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}

int Error=1;
void ErrorCheck(int check_what, int value);


int main()
{   

   int a=0,b=0,c=0,f=0,t=0;
   int runonce=0;

   while(Error==1)
   {      
      cout << "What Will Be The First Number In The Sequence?: ";
      cin >> a;ErrorCheck(1,a);
   }

   Error=1;
   while(Error==1)
   {
      cout << "What Will Be The Second Number?: ";
      cin >> b;ErrorCheck(2,b);
   }

   Error=1;
   while(Error==1)
   {
      cout << "How Many Numbers Should Be Displayed?: ";
      cin >> t;ErrorCheck(3,t);
   }

   //==Algorithm=========================   

   for(int x=2;x<t;x++)
   {
      if(runonce==0)
      {cout<<"["<<a<<"]\n";cout<<"["<<b<<"]\n";runonce=1;}
      
      if(a+b<-10000)
      {
         cout<<"RUNTIME ERROR: Interger Values Too Large To Represent..";
         cout<<"Ending Printout";break;
      
      }
   //==cpu====== or w/e make that 'fibbonacci p u'
      c=a+b;   
      cout<<"["<<c<<"]\n";
      a=b;
      b=c;
   //===========

   //====================================
      
   }

   cout<<"\n\n";
   system("pause");
   return 0;

}// int MAIN();

void ErrorCheck(int check_what, int value)
{
   if(check_what == 1)
   {
      if(value>5000||value<0)
      {
         gotoxy(0,0);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,0);cout<<"ERROR: First Number Range From 0 to 5000";
         Error=1;gotoxy(0,23);system("pause");gotoxy(0,0);
         gotoxy(0,0);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,23);for(int x=0;x<78;x++)cout<<" ";gotoxy(0,0);
      }
      else
      {gotoxy(0,2);Error=0;}
   } //1st number

   if(check_what == 2)
   {
      if(value>10000||value<0)
      {
         gotoxy(0,2);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,2);cout<<"ERROR: Second Number Range From 0 to 10000";
         Error=1;gotoxy(0,23);system("pause");
         gotoxy(0,2);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,23);for(int x=0;x<78;x++)cout<<" ";gotoxy(0,2);
      }
      else
      {gotoxy(0,4);Error=0;}
   } //2nd number


   if(check_what == 3)
   {
      if(value<3)
      {
         gotoxy(0,4);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,4);cout<<"ERROR: Sequence Must Contain Atleast 3 Numbers!";
         Error=1;gotoxy(0,23);system("pause");
         gotoxy(0,4);for(int x=0;x<78;x++)cout<<" ";
         gotoxy(0,23);for(int x=0;x<78;x++)cout<<" ";gotoxy(0,4);
      }
      else
      {gotoxy(0,5);for(int x=0;x<79;x++)cout<<"=";gotoxy(0,6);Error=0;}
   } //(t)

   

   if(value>10000||value<0)
   {
   //   gotoxy(0,3);for(int x=0;x<78;x++)cout<<" ";
   //   
   }
   
}//void ErrorCheck();
Last edited by glinka57 on Thu Oct 29, 2009 10:52 am, edited 1 time in total.
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: Fibonacci sequence practice problem

Postby Vevix on Wed Oct 28, 2009 11:03 pm

@ glinka57

:) Still using globals!! Well global, You edited your code while i wrote this part out lol

Code: Select all
cout<<"RUNTIME ERROR: Interger Values Too Large To Represent...";


Look into try/catch blocks, C style error checking (if statements) isn't fun!

an example would be:

Code: Select all
// Main function!
int main()
{
   // Example of try/catch blocks
   try
   {
      // Code for whatever goes here..

      // Example error throw
      throw std::runtime_error("I'm an Error, yay!");
   }
   catch (const std::exception& e) // Catch exception thrown
   {
      // Output the error
      std::wcout << "General Error: " << e.what() << std::endl;
   }
   catch (...) // Unknown error
   {
      // Output the error
      std::wcout << "Unknown Error" << std::endl;
   }
}


with the output being: "General Error: I'm an Error, yay!"

With this other functions can throw exceptions like above, and be caught if the function call is within a try block (like main in the example)

@ noobgrammer

the second is you are using VS so get rid of the system pause and just run it with ctrl+F5 and you will not need the system pause.


Needed for people who run the program outside of an IDE; Tho you should be using the std::cin.get() method posted in the other thread
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup
User avatar
Vevix
 
Posts: 142
Joined: Sat Oct 10, 2009 9:24 pm
Location: kernel32.dll

Re: Fibonacci sequence practice problem

Postby noobgrammer on Thu Oct 29, 2009 9:58 am

lol I love it glinka now there is some creativity there with a error check I have to say I would never have expected to see a code like that.

maybe one day antiRTFM will make a vid on try throw and catch, for some reason they confuse me even though it looks like it should be simple concept to understand oh well I'm sure one day it will click in my head and make full sense.

and Vevix very true with running it outside a compiler, though I have read all the negativity about using all that stuff to pause a program even the std::cin.get(), but then that is more for when you have a actual program worth handing out to anybody
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: Fibonacci sequence practice problem

Postby willchen298 on Mon Nov 30, 2009 11:08 pm

D: .. weird code.. huh?

Code: Select all
/*
   FIBONACCI SEQUENCE
   -----------------
   WRITTEN BY: ~~
   WRITTEN ON: 6:42 PM, 11/30/09
   
   Finds the fibonacci numbers
   on a user-defined amout of
   times. [recursive]
*/

#include <iostream>
using namespace std;
int fibonacci(int times);
int main()
{
   int times;
   cout << "How many times do you want to run the fibonacci sequence? ";
   cin >> times;
   for(int i = 1; i<=times; i++)
   {
         if(i==times)
         {
            cout << fibonacci(i) << " ";
         }
         else
         {
         cout << fibonacci(i) << ", ";   
         }
   }
   
   cout << endl;
   
   return 0;
}

int fibonacci(int times)
{
   if(times == 1)
   {
      return 1;
   }
   if(times == 0)
   {
      return 0;
   }
   else
   {
      return fibonacci(times-1)+fibonacci(times-2);
   }
}
willchen298
 
Posts: 1
Joined: Mon Nov 30, 2009 11:06 pm


Return to Projects

Who is online

Users browsing this forum: No registered users and 0 guests