如何使用C#计算幂指数值?
要计算幂指数值,请使用Math.pow()方法。
在这里,n是数字,p是幂-
double res = Math.Pow(n, p);
以下是完整的代码-
示例
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();
}
}输出结果
Exponent Power= 7 Result= 343