After execution of the following code what is the value of t
After execution of the following code, what is the value of the int variable N if the user inputs the value 5? (The following code may have been indented incorrectly) cin > greaterthan N; if(N 2) N = N - 5; 15 10 25 None of the answers provided 5
Solution
Even if the code is indented incorrectly, the code gets indented automatically as follows:
if(N < 10)
if(N > 2)
N = N - 5;
1. Initially Value N is tested using first if condition ( N < 10 )
1.1 If first if condition is satisfied, then tests for second if condition ( N > 2 )
1.1.1 If second if condition is satisfied, then executes the line N = N - 5
User enters value 5 for Variable N.
First if condition is satisfied ( 5 < 10 )
Second if condition is satisfied ( 5 > 2 )
N value is updated as 0 ( 5 - 5 )
So the final value of N after executing the above code is 0
Hence the correct answer is 0 (Zero).
