
在复数里,real 表示取实部函数。
应当用小写
#include <complex>
#include <iostream>
int main( )
{
using namespace std
complex <double>c1 ( 4.0 , 3.0 )// c1 是复数
cout <<"The complex number c1 = " <<c1 <<endl
double dr1 = real ( c1 ) // 取c1的实部
cout <<"The real part of c1 is real ( c1 ) = "
<<dr1 <<"." <<endl
double di1 = imag ( c1 ) // 取c1的虚部
cout <<"The imaginary part of c1 is imag ( c1 ) = "
<<di1 <<"." <<endl
}
上面程序 输出
The complex number c1 = (4,3)
The real part of c1 is real ( c1 ) = 4.
The imaginary part of c1 is imag ( c1 ) = 3.
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)