- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Math.Sqrt() Method in C#
The Math.Sqrt() method in C# is used to compute the square root of the specified number.
Syntax
Following is the syntax −
public static double Sqrt (double val);
Above, Val is the number for which we want the square root.
Example
Let us now see an example to implement Math.Sqrt() method −
using System; public class Demo { public static void Main(){ double val1 = 4; double val2 = 36; Console.WriteLine(Math.Sqrt(val1)); Console.WriteLine(Math.Sqrt(val2)); } }
Output
This will produce the following output −
2 6
Example
Let us see another example to implement Math.Sqrt() method −
using System; public class Demo { public static void Main(){ double val1 = -144; double val2 = 0.49; Console.WriteLine(Math.Sqrt(val1)); Console.WriteLine(Math.Sqrt(val2)); } }
Output
This will produce the following output −
NaN 0.7
Advertisements