What will be the output of the following C# code? [code] static void Main(string[] args) { int m = 10, n = 5, p = 20; bool

Khang Lê

New member
What will be the output of the following C# code?
Code:
 static void Main(string[] args)
 {
     int m = 10, n = 5, p = 20;
     bool b1 =  m * p / n <= p * n / m ;
     int l = p - 2 * m;
     bool b2 = l == 0;
     int z = Convert.ToInt32(b2);
     int k = Convert.ToInt32(b1);
     Console.WriteLine(k);
     Console.WriteLine(z);
 }
A. 0 0
B. 1 0
C. 0 1
D. 1 1
 
Answer: c
Explanation: Solving the expression for b1 tests the condition for either true or false result in '0'. Similarly, for 'b2' 'l' on solving gives '0'. So, condition is true for bool b2 as 0 == 0. Hence, k = 0 and z = 1.
Output :
Code:
0 1.
 

Tìm kiếm

Back
Top