How many times is the comparison i > = n performed in the followin...
It will start comparison from (85, 5), (84, 6), (83, 7) .............. (45, 45), (44, 46)
Hence total number of comparison will be (85-44) + 1 = 41 + 1 = 42
View all questions of this test
How many times is the comparison i > = n performed in the followin...
Explanation:
In the given program, the comparison i = n is performed multiple times within the while loop. Let's break down the program step by step to determine the number of times the comparison is performed.
1. Initialize variables:
i = 85
n = 5
2. Enter the while loop:
while (i = n) {
3. At this point, the value of i is 5, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 4
n = n + 1; // n becomes 6
4. The loop condition is re-evaluated:
while (i = n) {
5. At this point, the value of i is 6 and the value of n is 6, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 5
n = n + 1; // n becomes 7
6. The loop condition is re-evaluated:
while (i = n) {
7. At this point, the value of i is 7 and the value of n is 7, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 6
n = n + 1; // n becomes 8
8. The loop condition is re-evaluated:
while (i = n) {
9. At this point, the value of i is 8 and the value of n is 8, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 7
n = n + 1; // n becomes 9
10. The loop condition is re-evaluated:
while (i = n) {
11. At this point, the value of i is 9 and the value of n is 9, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 8
n = n + 1; // n becomes 10
12. The loop condition is re-evaluated:
while (i = n) {
13. At this point, the value of i is 10 and the value of n is 10, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 9
n = n + 1; // n becomes 11
14. The loop condition is re-evaluated:
while (i = n) {
15. At this point, the value of i is 11 and the value of n is 11, so the condition (i = n) is true. The code within the loop executes:
i = i - 1; // i becomes 10
n = n + 1; // n becomes 12
16. The loop condition is re-evaluated:
while (i = n) {
17. At this point, the value of i is
How many times is the comparison i > = n performed in the followin...
u can check it by writing manually in a short way.