Write a C++ Program that asks the user to type an Integer N and
compute the u(N) defined by u(0) =3
u(n+1) = 3*u(n)+4
HI, Please find my implementation of U(int n) function.
Please let me know in case of any issue.
#include <iostream> // input/output library
using namespace std;
int U(int n){
// base case
if(n == 0)
return 3;
// recursive call
return 3*U(n-1)+4;
}
int main(){
int n;
cout<<"Enter value of n: ";
cin>>n;
cout<<"U("<<n<<") : "<<U(n)<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.