Find the output of the following:
y= x<1000?400:300;
1) x=500 2) x=1050
Answers
Answered by
3
Required Answer:-
Given Códe:
To Find:
- The output of the given códe when x = (i) 500, (ii) 1050
Solution:
When x = 500,
Check if the condition is true or not?
→ Is 500 < 1000? - Yes. It's true.
So, 'y' will store the first value, written after ?.
★ So, the final value of y is 400.
Again, when x = 1050,
Check if the condition is true or not?
→ Is 1050 < 1000? - No. It's false.
So, 'y' will store the second value, written after :.
★ So, the final value of y is 300.
Answer:
- 400
- 300
•••♪
Answered by
4
Answer (1):
- when x=500,
500<1000, condition true.
therefore, y will store 400
Answer (2):
- when x=1050,
1050<1000, condition false
therefore y will store 300
Similar questions