C++ 中複雜數字的 pow() 函式


pow() 或冪函式是一個函式,用於計算一個數的冪。它通常用於實數。在此,我們將看到其在複數中的實現。

複數是指可以表示為A + iB 的數,其中 A 是實部,B 是該數的虛部。

c++ 中複數的函式在標頭檔案 <complex.h> 中定義。在此,定義了複數的 pow() 方法。它找到複數的複數冪到某次冪。

應用於複數的方法採用兩個輸入引數,第一個是複數基數 (C),然後是指數 (a)。它返回一個複數 C^a。

輸入 − C = 4 + 3i a = 2

輸出 − (7, 24)

示例

用於查詢複數的 pow 的程式

 即時演示

#include <iostream>
#include <complex>
using namespace std;
int main() {
   complex<double> complexnumber(4, 3);
   cout<<"Square of (4+ 3i) = "<<pow(complexnumber, 2)<<endl;
   return 0;
}

輸出

Square of (4+ 3i) = (7,24)

更新於: 17-4-2020

589 次瀏覽

職業生涯啟動計劃

完成課程就會得到認證

開始學習
廣告
© . All rights reserved.