C# Math Pow

Description

Math Pow returns a specified number raised to the specified power.

Syntax

Math.Pow has the following syntax.


public static double Pow(
  double x,
  double y
)

Parameters

Math.Pow has the following parameters.

  • x - A double-precision floating-point number to be raised to a power.
  • y - A double-precision floating-point number that specifies a power.

Returns

Math.Pow method returns The number x raised to the power y.

Example

The following example uses the Pow method to calculate the value that results from raising 2 to a power ranging from 0 to 32.


using System;/*  w w  w  .  j  ava2 s.  c  om*/

public class Example
{
   public static void Main()
   {
      int value = 2;
      for (int power = 0; power <= 32; power++)
         Console.WriteLine("{0}^{1} = {2:N0} (0x{2:X})", 
                           value, power, (long)Math.Pow(value, power));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version