C++/Data Type/Complex

Материал из C\C++ эксперт
Перейти к: навигация, поиск

complex number plus another complex number

  
#include <iostream>
#include <complex>
using namespace std;
   
int main()
{
  complex<double> cmpx1(1, 0);
  complex<double> cmpx2(1, 1);
   
  cout << cmpx1 << " " << cmpx2 << endl;
   
  complex<double> cmpx3 = cmpx1 + cmpx2;
  cout << cmpx3 << endl;
   
  cmpx3 += 10;
  cout << cmpx3 << endl;
   
  return 0;
}


Demonstrate complex.

 
#include <iostream>
#include <complex>
using namespace std;
int main()
{
  complex<double> cmpx1(1, 0);
  complex<double> cmpx2(1, 1);
  cout << cmpx1 << " " << cmpx2 << endl;
  complex<double> cmpx3 = cmpx1 + cmpx2;
  cout << cmpx3 << endl;
  cmpx3 += 10;
  cout << cmpx3 << endl;
  return 0;
}


Demonstrate the complex class.

  
#include <iostream>
#include <complex>
using namespace std;
int main()
{
  complex<double> cmpx1(1, 0);
  complex<double> cmpx2(1, 1);
  cout << "cmpx1: " << cmpx1 << endl << "cmpx2: " << cmpx2 << endl;
  cout << "cmpx1 + cmpx2: " << cmpx1 + cmpx2 << endl;
  cout << "cmpx1 * cmpx2: " << cmpx1 * cmpx2 << endl;
  cmpx1 += 2.0;
  cout << "cmpx1 += 2.0: " << cmpx1 << endl;
  cout << "sin(cmpx2): " << sin(cmpx2) << endl;
  return 0;
}