abs()函数可用于c + +中的复数?

C ++中的abs函数用于查找复数的绝对值。复数的绝对值(也称为模数)是该数与复数平面中的原点的距离。这可以使用公式找到-

对于复数a + bi:

mod|a+bi| = √(a2+b2)

abs()函数在C ++中返回上述计算的结果。它在需要包含的复杂库中定义。

abs()在C ++中显示对复数使用功能的程序

#include <iostream>
#include <complex>
using namespace std;
int main () {
   float a= 13.0 , b = 5.0;
   complex<double> complexnumber (a, b);
   cout << "The absolute value of " << a<<"+"<<b<<"i" << " is: ";
   cout << abs(complexnumber) << endl;
   return 0;
}

输出结果

The absolute value of 13+5i is: 13.9284