ProgrammingHard
int c = 0; for (int i = 0; i < 100; i++) c += i % 3 == 0; printf("%d", c); What is printed?
- A. 34
- B. 33
- C. 100
- D. 35
Correct answer: A. 34
The values 0, 3, ..., 99 are multiples of 3, which are 34 numbers. The comparison contributes 1 for each.
More C Programming questions
- unsigned n = 5; int c = 0; while (n-- > 0) c++; printf("%d", c); What is printed?
- int a = 0; for (int i = 0; i < 1000000; i++) a ^= i; printf("%d", a); What is printed?
- int x = 1, c = 0; while (x < 1000000000) { x = 3; c++; } printf("%d", c); What is printed (no overflow occurs)?
- 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?