MathF.Sqrt() Method in C# with Examples
Last Updated :
04 Apr, 2019
In C#, MathF.Sqrt(Single) is a MathF class(present in system namespace) method which is used to calculate the square root of the specified Single or float data type value.
Syntax: public static float Sqrt (float x);
Here, x is the number whose square root is to be calculated and type of this parameter is System.Single.
Return Type: This method returns the square root of x. If x is equal to NaN, NegativeInfinity, or PositiveInfinity, that value is returned. The return type of this method is System.Single.
Below are the examples to illustrate the use of the above-discussed method:
Example 1:
using System;
class GFG {
public static void Main()
{
float x = 78521F;
float x1 = -7824F;
Console.WriteLine(MathF.Sqrt(x));
Console.Write(MathF.Sqrt(x1));
}
}
|
Example 2:
using System;
class GFG {
public static void Main()
{
float x = 0f;
Console.WriteLine(MathF.Sqrt(x));
float y = -0f;
Console.Write(MathF.Sqrt(y));
}
}
|
Share your thoughts in the comments
Please Login to comment...