C# MCQs 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
Answer: a
Clarification: None.
2. Which of these methods is a rounding function of Math class?
a) Max()
b) Min()
c) Abs()
d) Round()
Answer: d
Clarification: 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
Answer: a
Clarification: Math class contains all the floating point functions that are used for general purpose mathematics methods. Example : sin(), cos(), exp(), sqrt() etc.
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)
Answer: a
Clarification: 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)
Answer: b
Clarification: 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
Answer: a
Clarification: Abs() returns the absolute value of a variable.
7. What will be the output of the following C# code snippet?
-
public class A
-
{ -
public int x;
-
public int y;
-
public void display()
-
{ -
Console.WriteLine(x + " " + y);
-
} -
} -
class Program -
{ -
static void Main(string[] args)
-
{ -
A obj1 = new A();
-
A obj2 = new A();
-
obj1.x = 1;
-
obj1.y = 2;
-
obj2 = obj1;
-
obj1.display();
-
obj2.display();
-
} -
}
a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) Run time exception
Answer: b
Clarification: None.
Output:
8. What will be the output of the following C# code snippet?
-
class Program -
{ -
static void Main(string[] args)
-
{ -
double x = 3.14;
-
int y = (int) Math.Abs(x);
-
Console.WriteLine(y);
-
} -
}
a) 0
b) 3
c) 3.0
d) 3.1
Answer: b
Clarification: None.
Output:
9. What will be the output of the following C# code snippet?
-
class Program -
{ -
static void Main(string[] args)
-
{ -
double x = 3.14;
-
int y = (int) Math.Ceiling(x);
-
Console.WriteLine(y);
-
} -
}
a) 0
b) 3
c) 3.0
d) 4
Answer: d
Clarification: Ceiling(double x) returns the smallest whole number greater than or equal to variable x.
Output:
10. What will be the output of the following C# code snippet?
-
class Program -
{ -
static void Main(string[] args)
-
{ -
double x = 3.14;
-
int y = (int) Math.Floor(x);
-
Console.WriteLine(y);
-
} -
}
a) 0
b) 3
c) 3.0
d) 4
Answer: b
Clarification: 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:
