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