complex - STL C++

norm()

Declaration

X norm(const complex<X>& kqrZ);

Description

This is the friend function norm() for complex numbers. It returns the norm of the complex number kqrZ. The formula for the norm of a complex number z = x + iy, for real numbers x and y is

norm(z) = sqrt(x² + y²).

Header Include

#include <complex>

Example

#include <complex>
#include <iostream>

int main()
{
	using namespace std;

	// Create a complex number and calculate its norm
	complex<double> qZ(2.0, 4.0);
	cout << "Complex Number : "<< qZ << endl;
	cout << "The norm is "<< norm(qZ) << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

norm() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.