ProgrammingVery hard
int x = 1, c = 0; while (x < 1000000000) { x *= 3; c++; } printf("%d", c); What is printed (no overflow occurs)?
- A. 18
- B. 20
- C. 9
- D. 19
Correct answer: D. 19
3^19 = 1162261467 is the first power of 3 that reaches 10^9, so the loop body runs 19 times.
More C Programming questions
- A linear search over an array of length n finds the value only at the last position. How many comparisons does it make?
- Bubble sort with a swapped flag stops early. On an already sorted array of length n, how many passes run?
- A recursive binary search on n = 1000 sorted values reaches what maximum recursion depth?
- Merge sort on n = 2^20 elements has what recursion depth?
- An algorithm does O(n) work on each of the n levels of a recursion that removes one element per level. Which total is correct?
- A loop calls strlen(s) on a fixed string of length 10^4 once per character of the same string. How many characters are read in total?