How to calculate the power exponent value using C#?


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

921 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements