What will be the output of the following code?
#include void main() { int s=0; while(s++<10) { if(s<4 && s<9) continue; printf("%dt", s); } }
A.1 2 3 4 5 6 7 8 9
B.1 2 3 10
C.4 5 6 7 8 9 10
D.4 5 6 7 8 9
Answers
Answered by
27
B. 1 2 3 10
Hope it helps u
Hope it helps u
Answered by
0
Answer:
The output of the given code will be C.4 5 6 7 8 9 10
Explanation:
- The variable s is declared and initialized to value zero.
- The while loop condition checks whether the value of s is less than 10. After checking the condition, the value of variable s is incremented irrespective of the result.
- If it is less than 10, the while loop is run. Inside the while loop, there is an if statement present.
- The if statement checks whether the value of s is less than 4 and less than 9 and logically AND it.
- If the value of s is less than 4 as well as 9, the result after logically AND will be true(1). In all other cases, the result will be false(0).
- If the result is true implying that the number is smaller than 4, the next iteration of the while loop is carried out.
- If the result is false implying that the number is greater than 3, the value of s is printed and the next iteration of the while loop is executed.
- Once all the iterations of the while loop are executed, the final output is the values of s greater than 3.
Therefore, the output for the given code is 4 5 6 7 8 9 10.
#SPJ3
Similar questions