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
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?
class Program
{
static void Main(string[] args)
{
double x = 2.0;
double y = 3.0;
double z = Math.Pow( x, y );
Console.WriteLine(z);
Console.ReadLine();
}
}
a) 2.0
b) 4.0
c) 8
d) 8.0
View Answer
Explanation: None.
Output :
8
3. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
double x = 4.772;
double y = 4.76;
double z = Math.Max(x, y);
Console.WriteLine(z);
Console.ReadLine();
}
}
a) true
b) false
c) 4.772
d) 4.76
View Answer
Explanation: None.
Output :
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
Explanation: None.
5. 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
View Answer
Explanation: None.
Output :
1 2 1 2
6. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1 };
var posNums = from n in nums
select Math.Pow(4 ,3);
Console.Write("The values in nums: ");
foreach (int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
a) Run time error
b) 64
c) Compile time error
d) 81
View Answer
Explanation: None.
Output :
64
7. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
float x = 3.14F;
int y = (int)Math.Abs(x);
Console.WriteLine(y);
Console.ReadLine();
}
}
a) Compile time error
b) 3.14
c) 3
d) 4
View Answer
Explanation: None.
Output :
3
8. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int x = 5;
int y = (int)Math.Pow(x,2);
int z = (int)Math.Pow(y, 2);
Console.WriteLine(z);
Console.ReadLine();
}
}
a) 25
b) 625
c) Compile time error
d) Run time error
View Answer
Explanation: y = 25, z = 25*25 = 625
Output :
625
9. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = {3 ,1 ,2 ,5 ,4};
var ltAvg = from n in nums
let x = nums.Average()
where n < x
select n;
Console.WriteLine("The average is " + nums.Average());
Console.ReadLine();
}
}
a) Run time error
b) 3
c) 5
d) Compile time error
View Answer
Explanation: Built in method of maths class Avg() id used
Output :
3
10. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int y = (int)Math.Max(4,2);
int z = (int)Math.Pow(y, 2);
Console.WriteLine(z);
Console.ReadLine();
}
}
a) 4
b) Compile time error
c) 16
d) 89
View Answer
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.
- Apply for C# Internship
- Apply for Computer Science Internship
- Check C# Books
- Practice Computer Science MCQs
- Check MCA Books