Menu

(Solved) : Consider Following Iterative Function Int Pentagonal Int N Int Result 0 Int 1 Q26196737 . . .

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


Answer to Consider Following Iterative Function Int Pentagonal Int N Int Result 0 Int 1 Q26196737 . . .

OR