C# Question & Answers on Maths Class for Freshers

https://www.computersprofessor.com/2018/07/c-question-answers-on-maths-class-for.html
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?
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
b) 4.0
c) 8
d) 8.0
Answer: c
Output :8
3. What will be the output of the given 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
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?
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
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?
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
b) 64
c) Compile time error
d) 81
Answer: b
Output :64
7. What will be the output of the given 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
b) 3.14
c) 3
d) 4
Answer: c
Output :3
8. What will be the output of the given 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
b) 625
c) Compile time error
d) Run time error
Answer: b
Explanation: y = 25 , z = 25*25 = 625
Output :625
Output :625
9. What will be the output of the given 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
b) 3
c) 5
d) Compile time error
Answer: b
Explanation: Built in method of maths class Avg() id used
Output :3
Output :3
10. What will be the output of the given 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
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