C# Question & Answers on Maths Class for Freshers

1. Which of these classes contains only floating point functions?

a) Math
b) Process
c) System
d) Object
Answer: a

Explanation: Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.
2. What will be the output of the given code snippet?
  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          double x = 2.0;  
  6.          double y = 3.0;
  7.          double z = Math.Pow( x, y );
  8.          Console.WriteLine(z);
  9.          Console.ReadLine();
  10.      }
  11.  }
a) 2.0
b) 4.0
c) 8
d) 8.0
Answer: c
Output :8
3. What will be the output of the given code snippet?
  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          double x = 4.772;
  6.          double y = 4.76;
  7.          double z = Math.Max(x, y);
  8.          Console.WriteLine(z);
  9.          Console.ReadLine();
  10.      }
  11.  }
a) true
b) false
c) 4.772
d) 4.76
Answer: c
Output :4.772
4. What is the value of double constant ‘E’ defined in Math class?

a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0
Answer: c
5. What will be the output of the given code snippet?
  1.  public class A
  2.  {
  3.      public int x;
  4.      public int y;
  5.      public void display() 
  6.      {
  7.          Console.WriteLine(x + " " + y);
  8.      }
  9.  }
  10.  class Program
  11.  {
  12.      static void Main(string[] args)
  13.      {
  14.          A obj1 = new A();
  15.          A obj2 = new A();
  16.          obj1.x = 1;
  17.          obj1.y = 2;
  18.          obj2 = obj1;
  19.          obj1.display();
  20.          obj2.display();
  21.      }
  22.  }
a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) Run time exception
Answer: b
Output : 1 2 1 2
6. What will be the output of the given code snippet?
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[] nums = { 1 };
  6.         var posNums = from n in nums
  7.                       select Math.Pow(4 ,3);
  8.         Console.Write("The values in nums: ");
  9.         foreach (int i in posNums) 
  10.         Console.Write(i + " ");
  11.         Console.WriteLine();
  12.         Console.ReadLine();
  13.     }
  14. }
a) Run time error
b) 64
c) Compile time error
d) 81
Answer: b
Output :64
7. What will be the output of the given code snippet?
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         float x = 3.14F;
  6.         int y = (int)Math.Abs(x);
  7.         Console.WriteLine(y);
  8.         Console.ReadLine();
  9.     }
  10. }
a) Compile time error
b) 3.14
c) 3
d) 4
Answer: c
Output :3
8. What will be the output of the given code snippet?
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int x = 5;
  6.         int y = (int)Math.Pow(x,2);
  7.         int z = (int)Math.Pow(y, 2);
  8.         Console.WriteLine(z);
  9.         Console.ReadLine();
  10.     }
  11. }
a) 25
b) 625
c) Compile time error
d) Run time error
Answer: b
Explanation: y = 25 , z = 25*25 = 625
Output :625
9. What will be the output of the given code snippet?
  1.  class Program
  2.  {
  3.      static void Main(string[] args)
  4.      {
  5.          int[] nums = {3 ,1 ,2 ,5 ,4};
  6.          var ltAvg = from n in nums
  7.                      let x = nums.Average()
  8.                      where n < x
  9.                      select n;
  10.          Console.WriteLine("The average is " + nums.Average());
  11.          Console.ReadLine();
  12.      }
  13.  }
a) Run time error
b) 3
c) 5
d) Compile time error
Answer: b
Explanation: Built in method of maths class Avg() id used
Output :3
10. What will be the output of the given code snippet?
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int y = (int)Math.Max(4,2);
  6.         int z = (int)Math.Pow(y, 2);
  7.         Console.WriteLine(z);
  8.         Console.ReadLine();
  9.     }
  10. }
a) 4
b) Compile time error
c) 16
d) 89
Answer: c

Explanation: Built in method of maths class, Max() is used to select maximum value among 4 and 2 and then y is squared using Pow() of math class and the value is stored in z.
Output :16

Related

Multiple Choice Questions and Answers for If-then-else Statements in C Language

1. The output of the code below is #include void main() { int x = 5; if (x < 1) printf("hello"); if (x == 5) printf("hi...

Data Structures Multiple Choice Questions and Answers on Towers of Hanoi

1. Which data structure can be used suitably to solve the Tower of Hanoi problem? a) Treeb) Heapc) Priority queued) Stack Answer: d Explanation: The Tower of Hanoi involves moving of disks ‘stack...

Multiple Choice Questions and Answers for – Conditional Expressions in C Language

1. What is the output of this C code? #include int main() { int x = 2, y = 0; int z = (y++) ? y == 1 && x : 0; printf("%d\n", z); r...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item