C# Tutorial
System namespace contains the Math class which has Sqrt method to perform square root value for given double value.
double Math.Sqrt(double)
/* This C# program to calculate square root value of number. Also added single and multiline comments. */ using System; // System is a namespace public class SqrtCalc { // Main method which starts the program execution. public static void Main() { // Declaration and initialization double num = 36.0; // Variable declaration double sqrtVal; sqrtVal = Math.Sqrt(num); Console.WriteLine("Square Root Value (" + num + ")" + ": " + sqrtVal); // Waits for any key press Console.ReadKey(); } }
Output:
C:> csc SqrtCalc.cs C:> SqrtCalc Square Root Value (36): 6
We can also pass the float number instead of double number (implicit type casting) to Math.Sqrt mmethd and returns double value.
/* This C# program to calculate square root value of number. Also added single and multiline comments. */ using System; // System is a namespace public class SqrtCalc { // Main method which starts the program execution. public static void Main() { // Declaration and initialization float num = 36.0F; // Variable declaration double sqrtVal; sqrtVal = Math.Sqrt(num); Console.WriteLine("Square Root Value (" + num + ")" + ": " + sqrtVal); // Waits for any key press Console.ReadKey(); } }
Output:
C:> csc SqrtCalc.cs C:> SqrtCalc Square Root Value (36): 6
We can also pass the integer number instead of double number (implicit type casting) to Math.Sqrt method and returns double value.
/* This C# program to calculate square root value of number. Also added single and multiline comments. */ using System; // System is a namespace public class SqrtCalc { // Main method which starts the program execution. public static void Main() { // Declaration and initialization int num = 36; // Variable declaration double sqrtVal; sqrtVal = Math.Sqrt(num); Console.WriteLine("Square Root Value (" + num + ")" + ": " + sqrtVal); // Waits for any key press Console.ReadKey(); } }
Output:
C:> csc SqrtCalc.cs C:> SqrtCalc Square Root Value (36): 6
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page