What is Math.Sqrt() in C#?
C# has a built-in Math class that provides useful mathematical functions and operations. The Math class has the Sqrt() function, which is used to compute the square root of a specified number.
Syntax
public static double Sqrt (double value);
Parameters
value:valueis of theDoubletype and represents the input value for which we have to findSqrt(). Its range is all double numbers.
Return value
Double:Sqrt()returns aDoublenumber representing the square root of thevalue.NaN:Sqrt()returnsNaNtype for negative numbers orNaNinput invalue.PositiveInfinity:Sqrt()returnsPositiveInfinityfor thePositiveInfinityinput invalue.
Example
using System;class Educative{static void Main(){Double result = Math.Sqrt(-0.16);System.Console.WriteLine("Sqrt(0.16) = "+ result);Double result1 = Math.Sqrt(0);System.Console.WriteLine("Sqrt(0) = "+ result1);Double result2 = Math.Sqrt(16);System.Console.WriteLine("Sqrt(16) = "+ result2);Double result3 = Math.Sqrt(Double.PositiveInfinity);System.Console.WriteLine("Sqrt(∞) = "+ result3);Double result4 = Math.Sqrt(Double.NegativeInfinity);System.Console.WriteLine("Sqrt(-∞) = "+ result4);}}