如何使用 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

更新于:20-6 月-2020

1000+ 查看

开启 职业生涯

完成本课程即可获得认证

开始学习
广告
© . All rights reserved.