- The function $F(n)$ is NOT a recursive function. You can't have a recurrence relation for it in the first place!
- $F(n)$ calculates $(n-1)^n$.
The equivalent C++ code is as follows: (You can try it out here: http://ideone.com/w0u4lk)
long F(long n) {
long F1 = 1;
if(n==1) { return 3; }
else {
for(long i = 1; i <= n; i++) {
long C = 0;
// Note: the belore For loop only has one line
for(long j = 1; j <= n-1; j++) { C = C+1; }
// At the end of this for loop, C will be = (n-1)
F1 = F1 * C;
}
}
return F1;
}
It is clear that the inner for loop can be replaced by a single statement as follows:
long F(long n) {
long F1 = 1;
if(n==1) { return 3; }
else {
for(long i = 1; i <= n; i++)
F1 = F1 * (n-1);
}
return F1;
}
And this calculates $(n-1)^n$