C# Math.Pow() – Examples
In this tutorial, we will learn about the C# Math.Pow() method, and learn how to use this method to find the result of a number raised to a specified power, with the help of examples.
Pow(Double, Double)
Math.Pow(x, y) returns the value of specified number x
raised to the specified power y
.
ADVERTISEMENT
Syntax
The syntax of Pow() method is
Math.Pow(Double x, Double y)
where
Parameter | Description |
---|---|
x | A double-precision floating-point number to be raised to a power. |
y | A double-precision floating-point number that specifies a power. |
Return Value
The method returns Double value.
Example 1 – Pow(x, y)
In this example, we will take different values for x and y, and compute the value of x raised to the power y using Math.Pow() method.
C# Program
using System; class Example { static void Main(string[] args) { Double x, y, result; x = 2; y = 3; result = Math.Pow(x, y); Console.WriteLine($"Pow({x},{y}) = {result}"); x = -1; y = 3; result = Math.Pow(x, y); Console.WriteLine($"Pow({x},{y}) = {result}"); x = 4; y = 2; result = Math.Pow(x, y); Console.WriteLine($"Pow({x},{y}) = {result}"); x = 9; y = 0.5; result = Math.Pow(x, y); Console.WriteLine($"Pow({x},{y}) = {result}"); x = 1; y = 0; result = Math.Pow(x, y); Console.WriteLine($"Pow({x},{y}) = {result}"); } }
Output
Pow(2,3) = 8 Pow(-1,3) = -1 Pow(4,2) = 16 Pow(9,0.5) = 3 Pow(1,0) = 1
Conclusion
In this C# Tutorial, we have learnt the syntax of C# Math.Pow() method, and also learnt how to use this method with the help of C# example programs.