Home »
.Net
C#.Net Math Class and Its Methods
C#.Net Math Class and Its Methods: Learn C# Math Class’s Methods with Example, this post contains list of C#.Net Math class’s methods.
Math is a pre-defined class in C#.Net, which has many methods to perform mathematical operations without using operators for that.
This post contains some of the common and most popular Math class’s methods which may help you to perform related operations in C# program.
These are following important methods are used in c#:
- Math.Pow()
- Math.Sqrt()
- Math.Max()
- Math.Min()
- Math.Ceiling()
- Math.Floor()
1) Math.Pow()
This method is used to calculate power of given number.
2) Math.Sqrt()
This method is used to calculate square root of given number.
3) Math.Max()
This method is used to find largest number from two given number.
4) Math.Min()
This method is used to find smallest number from two given number.
5) Math.Ceiling()
This method is used to ceil given floating point number.
6) Math.Floor()
This method is used to floor given floating point number.
Consider the program:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double num = 0;
double power = 0;
double result = 0;
Console.Write("Enter Number : ");
num = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Power : ");
power = Convert.ToDouble(Console.ReadLine());
result = Math.Pow(num, power);
Console.WriteLine("Result : " + result);
result = Math.Sqrt(16);
Console.WriteLine("Result : " + result);
result = Math.Max(10.2, 10.5);
Console.WriteLine("Result : " + result);
result = Math.Min(10.2, 10.5);
Console.WriteLine("Result : " + result);
result = Math.Ceiling(10.2);
Console.WriteLine("Result : " + result);
result = Math.Floor(10.2);
Console.WriteLine("Result : " + result);
}
}
}
Output
Enter Number : 2
Enter Power : 3
Result : 8
Result : 4
Result : 10.5
Result : 10.2
Result : 11
Result : 10