Consider the following iterative function:
int pentagonal(int n) {
int result =0;
for (int i =1; i <= n; i++)
result += 3 * i – 2;
returnresult;
}
Rewrite the function pentagonal using recursion and addpreconditions and postconditions as comments. Then prove byinduction that the recursive function you wrote is correct.
Please ensure you include the preconditions andpostcondtion comments and clearly prove byinduction step by step.
Expert Answer
An answer will be send to you shortly. . . . .