What will be the output of the following C# code? [code] int n = 2; int p = 4; int q = 5; int w = 3; if ( !((p * q)

Đức Linh

New member
What will be the output of the following C# code?
Code:
    int n = 2;
    int p = 4;
    int q = 5;
    int w = 3;
    if ( !((p * q) /n <= (q * w) + n/p ))
    {
        Console.WriteLine( ++p + w++ + " " + ++n);
        Console.WriteLine("b");
    }
    else
    {
        Console.WriteLine(--p + q-- + " " + --n);
        Console.WriteLine("a");
    }
A.
6 2
b
B.
8 1
a
C.
6 1
a
D.
8 1
b
 
Answer: b
Explanation: After evaluation of the test expression (!((p*q)/n <= (q*w)+n/p)). The use of logical operator(!) turns false(0) result to bit '1' and hence the condition evaluated by 'if' loop is after else as :
--p = 3
q--= 5
--p + q-- = 8 where now value of 'q'is 4.
--n = 2 - 1 =1.
So, values after evaluations are 8 1.
a.
Output :
Code:
         8 1
         a
 

Tìm kiếm

Back
Top