Complex numbers in C++

Asked

Viewed 1,131 times

5

I’m new to C++ and would like to know how to use complex numbers:

double real[2]={2,5};
double imaginario[2]{7,9};  
cout << "Soma: " << real[0]+real[1] << "+" << imaginario[0]+imaginario[1] << "i";

Is there a library for this?

1 answer

7


There is yes:

#include <iostream>
#include <complex>
using namespace std;

int main(){

    complex<double> a={2,7}, b={5,9};
    cout << "Soma: " << a+b;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.