well first he said that recursion was calling the same function that you're in with in that function
this is how he showed it to us:
/* Fibonacci sequence by recursion: this is inefficient since it calculates the same values many times. */#include <iostream.h>
int main() { int i; cout << "F(i) for what i? " << endl; //asks which number in the sequence you want cin >> i; //gets that number fib(i); //takes it to the function to calculate that number return 0; }
//calculates the number in the sequence that was asked for int fib(int i) { if (i==0 || i==1) return 1; else return fib(i-1) + fib(i-2); //this is the line of recursion: fib(i-1) + fib(i-2) the function is calling it's self. }
just thought that i would share what i'm learning in class, hope that someone finds it interesting :)

New Topic/Question
Reply




MultiQuote





|