如何使用 C# 计算幂指数值?


使用 Math.pow() 方法计算幂指数值。

其中,n 是数字,p 是幂 −

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

以下是完整代码 −

示例

 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();
   }
}

输出

Exponent Power= 7
Result= 343

更新日期: 20-6-2020

1K+ 阅读

开启您的职业生涯

完成课程并获得认证

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