Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Fibonacci series in c++ using recursion in C++

#include <iostream>

using namespace std;

int t1=0,t2=1,t3;

int fib (int k) {
t3 = t1 + t2;
t1 = t2;
t2 = t3;
cout<<" "<<t3;
if(--k>0) fib(k);
return 0;
}
main() {
start:
cout<<"\n\tEnter the no. of terms: ";
unsigned int n ;
cin>>n;

if(n>=2) {
cout<<"\n\t 0 1";
if(n>2) fib(n-2);
}
else if (n==1) cout<<" 0";
else {
cout<<"Terms must be greater than 0";
goto start;
}
return 0;
}