Computer Science, asked by aarongeorge27, 3 months ago

Find the output of the following:


y= x<1000?400:300;


1) x=500 2) x=1050​

Answers

Answered by anindyaadhikari13
3

Required Answer:-

Given Códe:

\tt &gt;&gt; y=(x&lt;1000)? \: 400:300;

To Find:

  • The output of the given códe when x = (i) 500, (ii) 1050

Solution:

When x = 500,

\tt &gt;&gt; y=(x&lt;1000)? \: 400:300

\tt &gt;&gt; y=(500&lt;1000)? \: 400:300

Check if the condition is true or not?

→ Is 500 < 1000? - Yes. It's true.

So, 'y' will store the first value, written after ?.

\tt &gt;&gt; y=400

So, the final value of y is 400.

Again, when x = 1050,

\tt &gt;&gt; y=(x&lt;1000)? \: 400:300

\tt &gt;&gt; y=(1050&lt;1000)? \: 400:300

Check if the condition is true or not?

→ Is 1050 < 1000? - No. It's false.

So, 'y' will store the second value, written after :.

\tt &gt;&gt; y=300

So, the final value of y is 300.

Answer:

  • 400
  • 300

•••♪

Answered by BrainlyProgrammer
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