各位大神们,请问C++中complex.h怎么用?
编程序需要用到复数运算,除了四则运算还包括自然对数运算等,请教一下complex头文件中怎么实现这些运算?非常感谢!!!
2012-12-06 11:13
2012-12-06 12:28
2012-12-06 12:52
程序代码:#include <iostream>
#include <complex>
using namespace std;
int main(int argc, char *argv[])
{
complex<double> a(1, 2), b(3, 4);
cout << "a = " << a << ", b = " << b << endl;
cout << "a + b = " << a + b << endl;
cout << "a * b = " << a * b << endl;
cout << "\nthe real part of a is " << real(a) << endl;
cout << "the imaginary part of b is " << imag(b) << endl;
cout << "the magnitude of a is " << abs(a) << endl;
cout << "\ne^a = " << exp(a) << endl;
cout << "ln(b) = " << log(b) << endl;
return 0;
}输出:
2012-12-06 20:53
2012-12-06 23:09
2012-12-07 21:54
2012-12-07 21:56
2012-12-07 21:56
2012-12-07 21:57
2012-12-10 11:37