1.Predit the ouput of the following code? static void Main(string[] args) { int a, b; int c = 10; int d = 12; int e = 5; int f = 6; a = c * (d + e) / f + d; Console.WriteLine(a); b = c * (d + e / f + d); Console.WriteLine(b); if (a != b) { Console.WriteLine(" Values are different"); } else { Console.WriteLine("Values are same"); } Console.ReadLine(); } A) Values are different B) Values are same C) Since both have equal values, no conclusion D) None of the mentioned View Answer Report DiscussAnswer: Option AExplanation:Solving the expression according to the priority of operators, we will ge the values of a and b are 40 and 240 respectively. So the correct answer is option a i.e Values are different
2.Correct order of priorities are : A) ‘/’ > ‘%’ > ‘*’ > ‘+’ B) ‘/’ > ‘*’ > ‘%’ > ‘+’ C) ‘*’ > ‘/’ > ‘%’ > ‘+’ D) ‘%’ > ‘*’ > ‘/’ > ‘+’ View Answer Report DiscussAnswer: Option C Explanation:Currently no explanation available Improve this answer lets discuss in forum
3.What will the output of the following set of code? static void Main(string[] args) { int a, b, c, x; a = 80; b = 10; c = 3; x = a - b / 3 + c * 2 - 1; Console.WriteLine(x); Console.ReadLine(); } A) 84 B) 82 C) 90 D) 80 View Answer Report DiscussAnswer: Option BExplanation:The order of evaluation happens according to the precedence of arithmetic operators.X = 80 – 10/3 + 3 * 2 – 1 10/3 = 3 3*2 = 6 80-3 = 77 77+6 = 83 83-1 = 82
4.What will be the output of the following set of code? static void Main(string[] args) { float a = 20.4f; int b = 15; float c; c = a * (b + a) / (a - b); Console.WriteLine("result is :" + c); Console.ReadLine(); } A) 133.7333 B) 132.7333 C) 135.7333 D) 133.76 View Answer Report DiscussAnswer: Option AExplanation:First (b+a) is calculated. Then this expression is multiplied by operand ‘a’ i.e a (b+a) and the whole result of numerator is combined and divided by denominator expression (a – b) .