Im trying to Write a Recursive funtion that computes F(n) = 2 + 4 + 6 +...+2n using pass by reference.. here is the code I have
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int F(int &);
int main(){
int n;
cout <<"Enter n for computing F(n) : ";
cin >> n;
cout <<"F( " << n <<" ) = " << F(n);
return 0;
}
int F(int &){
if ( n==0)
return 0;
if (n==1)
return 2;
else
return F(n-1) + (2 * n);
}
I keep getting an error any help would be greatly appreciated.