What is the number of iterations in the following loop int c
What is the number of iterations in the following loop:
int count = 5;
while (count < n) {
count = count + 3;
}
a. n - 5
b. n - 3
c. n / 3 - 1
d. (n - 5) / 3
e. the ceiling of (n - 5) / 3
Solution
Answer: e. the ceiling of (n - 5) / 3
Since count variable value is 5, when condition starts it will check like (n-5) < 0. Inside while loop we are addig 3 value in every iteration to the count variable so every iteration we are decresing n value with 3 and we should apply ceil on the value.
