Math.Pow() Method in C#


The Math.Pow() method in C# is used to compute a number raised to the power of some other number.

Syntax

Following is the syntax −

public static double Pow(double val1, double val2)

Above, val1 is a double-precision floating-point number to be raised to a power., whereas val2 is a double-precision floating-point number that specifies a power.

Example

Let us now see an example to implement Math.Pow() method −

using System;
public class Demo {
   public static void Main(){
      double res;
      res = Math.Pow(5, 0);
      Console.WriteLine("Math.Pow(5,0) = "+res);
      res = Math.Pow(0,5);
      Console.WriteLine("Math.Pow(0,5) = "+res);
   }
}

Output

This will produce the following output −

Math.Pow(5,0) = 1
Math.Pow(0,5) = 0

Example

Let us see another example to implement Math.Pow() method −

using System;
public class Demo {
   public static void Main(){
      int val1 = 10, val2 = 15;
      float val3 = 12.8f, val4 = 25.6f;
      double res = Math.Pow(3, 2);
      Console.WriteLine("Minimum Value from two int values = "+Math.Min(val1, val2));
      Console.WriteLine("Minimum Value from two float values = "+Math.Min(val3, val4));
      Console.WriteLine("Math.Pow(3,2) = "+res);
   }
}

Output

This will produce the following output −

Minimum Value from two int values = 10
Minimum Value from two float values = 12.8
Math.Pow(3,2) = 9

Updated on: 06-Nov-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements