注册 登录
编程论坛 C++教室

各位大神们,请问C++中complex.h怎么用?

Klaus19 发布于 2012-12-06 11:13, 7414 次点击
编程序需要用到复数运算,除了四则运算还包括自然对数运算等,请教一下complex头文件中怎么实现这些运算?
非常感谢!!!
10 回复
#2
w5277050902012-12-06 12:28
我百度了一下,你说的是一个复数类,你进去看一下里面的代码就知道怎么用了
#3
mmmmmmmmmmmm2012-12-06 12:52
#include"complex.h"
#4
pangding2012-12-06 20:53
有函数,直接用就行了:
程序代码:
#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;
}
输出:
a = (1,2), b = (3,4)
a + b = (4,6)
a * b = (-5,10)

the real part of a is 1
the imaginary part of b is 4
the magnitude of a is 2.23607

e^a = (-1.1312,2.47173)
ln(b) = (1.60944,0.927295)

#5
apollo3152012-12-06 23:09
关于这种标准模版库(STL)还有库函数之类的内容,网上有不少在线平台来查询的,比如goole一下,就能找到诸如www.之类的网站的,里边解释和举例很详细的。不要浪费网上的资源
#6
Klaus192012-12-07 21:54
回复 2楼 w527705090
谢谢啦!!
#7
Klaus192012-12-07 21:56
回复 3楼 mmmmmmmmmmmm
thank you!!
#8
Klaus192012-12-07 21:56
回复 4楼 pangding
谢谢帮助!很详细!
#9
Klaus192012-12-07 21:57
回复 5楼 apollo315
谢谢!我搜搜看
#10
jiafeiyang2012-12-10 11:37
C99中复数基本类型。通过float, double, or long double声明。   使用时须包含<complex.h>头文件,complex expands to _Complex
#11
青春无限2012-12-10 11:40
学习
1