C++ complex numbers, what is the right format?

前端 未结 5 518
闹比i
闹比i 2020-12-28 08:59

I want to use C++ with complex numbers. Therefore I included #include . Now my question is: How do I declare a variable?(so what is the format ca

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-28 09:23

    Here is an example of how to use . It compiles and runs under QT

    #include 
    #include
    #include
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    std::complex x=3.0-3.0i;
    std::complex y=2.0+4.0i;
    
    cout.precision(3);
    cout<<"x="< sum = x + y;
    cout<<"The sum: x + y = "< difference = x - y;
    cout<<"The difference: x - y = "< product = x * y;
    cout<<"The product: XY = "< quotient = x / y;
    cout<<"The quotient: x / y = "< conjugate = conj(x);
    cout<<"The conjugate of x = "< reciprocal = 1.0/x;
    cout<<"The reciprocal of x = "< exponential =exp(x);
    cout<<"The exponential  of x = "< pol= std::polar(2.0,(M_PI/180.0)*phase);
    cout<<"The polar: x , y = "<

提交回复
热议问题