Check the following C# code whether the given relation operator works according to the if condition or not. [code] static void Main(string[]

Check the following C# code whether the given relation operator works according to the if condition or not.
Code:
 static void Main(string[] args)
 {
     int a = 10;
     int b = 5;
     int c = 12; 
     int e = 8;
     int d;
     d = Convert.ToInt32((a * (c - b) / e + (b + c)) <= (e * (c + a) / (b + c) + a));
     Console.WriteLine(d);
     if (d == 1)
     {
         Console.WriteLine("C# is great language!");
         Console.WriteLine((a * (c - b) / e + (b + c)));
     }
     else
     {
         Console.WriteLine("harsh is not great language!");
         Console.WriteLine((e * (c + a) / (b + c) + a));
     }
 }
A.
0
C# is great!
20
B.
0
C# is not great!
25
C.
0
C# is great!
25
D.
0
C# is not great!
20
 
Answer: d
Explanation: The expression (a * (c - b) / e + (b + c)) on evaluation parenthesis by parenthesis gives result mathematically as 25. Similarly, (e * (c + a) / (b + c) + a) on evaluation parenthesis by parenthesis gives mathematically result as 20. Relational operator now checks for condition as in if condition as (25 < 20) which is false. So, a false bit in form of '0' is assigned to d. Now, in if condition (d != 1) as d = 0. So, condition after else is evaluated.
Output :
Code:
        0.
        C# is not great!.
        20.
 

Tìm kiếm

Back
Top