In problems 1 - 4, decide which answer best describes the loop invariant.
1. int count = 0; temp = 1; |
A. count < number B. temp equals base^(count - 1) C. temp equals count + 1 D. temp equals base^count E. temp equals base^(count + 1) |
2. int count = 1; |
A. temp equals number B. number equals count x tempC. count equals number / temp D. temp >= 10 E. (numdigits in number) - (numdigits in temp) + 1 equals count |
3. int Mystery(int num, int max) |
A. temp equals index x numB. temp equals (index - 1) x numC. temp equals (index + 1) x numD. temp equals index - 1 E. temp equals index |
4. const MAX =<some large integer> |
A. sum contains the value in items[0] B. sum contains the sum of the values in items[1] to items[place] C. sum contains the sum of the values in items[0] to items[MAX] D. sum contains the sum of the values in items[0] to items[place] E. place < MAX |
int Power(int base, int exp) // calculates base to the exp power { int i = _____; int j = _____; int k = _____; while (____________________) // invariant: i * j^k = base^ exp { _____________________; // gets closer _____________________; // restore invariant } return __________; }