

InterviewSolution
Saved Bookmarks
1. |
The following function is a part of some class. Assume ‘n’ is a positive integer. Answer the given questions along with dry run / working,int unknown (int n) { int i, k;if (n%2 = = 0) { i = n/2; k=1; } else { k=n; n--; i=n/2; } while (i > 0) { k=k*i*n; i--; n--; } return k; }(i) What will be returned by unknown(5)? (ii) What will be returned by unknown(6)? (iii) What is being computed by unknown (int n)? |
Answer» (i) 120 (ii) 720 (iii) calculate factorial/ product |
|