C#.Net Math Class and Its Methods

Math is a pre-characterized class in C#.Net, which has numerous techniques to perform numerical activities without utilizing administrators for that.

This post contains a portion of the normal and most famous Math class’ strategies which may assist you with performing related activities in the C# program.

These are the following significant strategies are utilized in c#:

  1. Math.Pow()
  2. Math.Sqrt()
  3. Math.Max()
  4. Math.Min()
  5. Math.Ceiling()
  6. Math.Floor()

1) Math.Pow()

This strategy is utilized to ascertain the intensity of the given number.

2) Math.Sqrt()

This strategy is utilized to ascertain the square base of the given number.

3) Math.Max()

This strategy is utilized to discover the biggest number from two given number.

4) Math.Min()

This strategy is utilized to discover the most modest number from two given number.

5) Math.Ceiling()

This strategy is utilized to ceil given skimming point number.

6) Math.Floor()

This strategy is utilized to floor given skimming point number.

Think about 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

Leave a Comment

error: Alert: Content is protected!!