Created
June 29, 2021 18:55
-
-
Save chbtoys/803c7a53e93e325ce3055ef0641f5ff4 to your computer and use it in GitHub Desktop.
Code examples. From Paper to Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Paper to Code | |
// Complex Numbers | |
// Run with: https://www.jdoodle.com/online-compiler-c++17/ | |
// LaTeX: 7 + 3i | |
// Test LaTeX: https://quicklatex.com/ | |
#include <iostream> | |
#include <complex> | |
int main() { | |
// defines the complex number: (7.0 + 3.0i) | |
std::complex<double> mycomplex (7.0, 3.0); | |
// prints the real part using the real function | |
std::cout << "Real part: " << real(mycomplex) << std::endl; | |
std::cout << "Imaginary part: " << imag(mycomplex) << std::endl; | |
// prints the absolute value of the complex number | |
std::cout << "The absolute value of " << mycomplex << " is: "; | |
std::cout << abs(mycomplex) << std::endl; | |
// prints the argument of the complex number | |
std::cout << "The argument of " << mycomplex << " is: "; | |
std::cout << arg(mycomplex) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment