C# Question & Answers – Maths Class

This section of our 1000+ C# MCQs focuses on maths class in C# Programming Language.

1. Which of these classes contains only floating point functions?
a) Math
b) Process
c) System
d) Object
View Answer

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 following C# 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
View Answer

Answer: c
Explanation: None.
Output :

advertisement
advertisement
8

3. What will be the output of the following C# 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
View Answer

Answer: c
Explanation: None.
Output :

advertisement
4.772

4. What is the value of double consonant ‘E’ defined in Math class?
a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0
View Answer

Answer: c
Explanation: None.
advertisement

5. What will be the output of the following C# 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
View Answer

Answer: b
Explanation: None.
Output :

 1 2 1 2

6. What will be the output of the following C# 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
View Answer

Answer: b
Explanation: None.
Output :

64

7. What will be the output of the following C# 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
View Answer

Answer: c
Explanation: None.
Output :

3

8. What will be the output of the following C# 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
View Answer

Answer: b
Explanation: y = 25, z = 25*25 = 625
Output :

625

9. What will be the output of the following C# 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
View Answer

Answer: b
Explanation: Built in method of maths class Avg() id used
Output :

3

10. What will be the output of the following C# 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
View Answer

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

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all areas of C# language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.