How to calculate the power exponent value using C#?

CsharpProgrammingServer Side Programming

To calculate the power exponent value, use the Math.pow() method.

Here, n is the number and p is the power −

double res = Math.Pow(n, p);

The following is the complete code −

Example

 Live Demo

using System;
class Program {
   static void Main() {
      double n, p;
      n = 7;
      p = 3;
      Console.WriteLine("Exponent Power= "+n);
      double res = Math.Pow(n, p);
      Console.WriteLine("Result= {0}", res);
      Console.ReadLine();
   }
}

Output

Exponent Power= 7
Result= 343
raja
Published on 08-Aug-2018 13:57:38
Advertisements