C# Questions & Answers – Rounding Functions

This section of our 1000+ C# MCQs focuses on rounding functions in C# Programming Language.

1. Which among the given classes provides types of rounding functions?
a) Math
b) Process
c) System
d) Object
View Answer

Answer: a
Explanation: None.

2. Which of these methods is a rounding function of Math class?
a) Max()
b) Min()
c) Abs()
d) Round()
View Answer

Answer: d
Explanation: Round() rounds up a variable to nearest integer.

3. 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 general purpose mathematics methods. Example : sin(), cos(), exp(), sqrt() etc.
advertisement
advertisement

4. Which of these method returns a smallest whole number greater than or equal to variable X?
a) double Ciel(double X)
b) double Floor(double X)
c) double Max(double X)
d) double Min(double X)
View Answer

Answer: a
Explanation: Ciel(double X) returns the smallest whole number greater than or equal to variable X.

5. Which of these methods return a largest whole number less than or equal to variable X?
a) double Ciel(double X)
b) double Floor(double X)
c) double Max(double X)
d) double Min(double X)
View Answer

Answer: b
Explanation: double Floor(double X) returns a largest whole number less than or equal to variable X.

6. Which of the following functions return absolute value of a variable?
a) Abs()
b) Absolute()
c) absolutevariable()
d) None of the mentioned
View Answer

Answer: a
Explanation: Abs() returns the absolute value of a variable.

7. What will be the output of the following C# code snippet?

advertisement
  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:

advertisement
 1 2 1 2

8. 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 = 3.14;  
  6.         int y = (int) Math.Abs(x);
  7.         Console.WriteLine(y);
  8.     }
  9. }

a) 0
b) 3
c) 3.0
d) 3.1
View Answer

Answer: b
Explanation: None.
Output:

  3

9. 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 = 3.14;  
  6.         int y = (int) Math.Ceiling(x);
  7.         Console.WriteLine(y);
  8.     }
  9. }

a) 0
b) 3
c) 3.0
d) 4
View Answer

Answer: d
Explanation: Ceiling(double x) returns the smallest whole number greater than or equal to variable x.
Output:

 4

10. 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 = 3.14;  
  6.         int y = (int) Math.Floor(x);
  7.         Console.WriteLine(y);
  8.     }
  9. }

a) 0
b) 3
c) 3.0
d) 4
View Answer

Answer: b
Explanation: double Floor(double X) returns the largest whole number less than or equal to variable X. Here, the smallest whole number less than 3.14 is 3.
Output:

 3

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.