EN
C# / .NET - Math.Pow() method example
0 points
Math.Pow()
is a static method that returns base raised to the power of exponent (value^exponent
operation).
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
public static void Main(string[] args)
6
{
7
// base exponent
8
Console.WriteLine( Math.Pow( 1 , 2 ) ); // 1
9
Console.WriteLine( Math.Pow( 2 , 2 ) ); // 4
10
Console.WriteLine( Math.Pow( 3 , 2 ) ); // 9
11
12
Console.WriteLine( Math.Pow( 0 , 3 ) ); // 0
13
Console.WriteLine( Math.Pow( 0.5, 0.3 ) ); // 0.8122523963562356
14
Console.WriteLine( Math.Pow( -1 , 4 ) ); // 1
15
16
Console.WriteLine( Math.Pow( 0 , -0.4 ) ); // ∞ / +Infinity
17
Console.WriteLine( Math.Pow( -0.5, -2 ) ); // 4
18
Console.WriteLine( Math.Pow( -2.0, -2 ) ); // 0.25
19
Console.WriteLine( Math.Pow( 2.0 , 0.5 ) ); // 1.4142135623730951
20
}
21
}
Syntax |
xxxxxxxxxx 1 namespace System 2 { 3 public static class Math 4 { 5 // ... 6 public static double Pow(double base, double exponent) { ... } 7 // ... 8 } 9 } |
Parameters |
The method takes a double arguments.
|
Result |
|
Description | Pow is a static method that returns base raised to the power of exponent (value^exponent operation). |