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