norm() function in C++ with Examples
The norm() function is defined in the complex header file. This function is used to return the squared magnitude of the complex number z. Syntax:
template<class T> T norm (const complex<T>& z);
Parameter:
- z: It represents the given complex number.
Return: It returns the squared magnitude of the complex number.
Time Complexity: O(1)
Auxiliary Space: O(1)
Below programs illustrate the above function:-
Example 1:-
CPP
// C++ program to demonstrate// example of norm() function.#include <bits/stdc++.h>using namespace std;// driver functionint main (){// initializing the complex: (5.0+12.0i)complex<double> complexnumber (5.0, 12.0);// use of norm()functioncout << "The norm of " << complexnumber << " is ";cout << norm(complexnumber) << endl;return 0;} |
Output:
The norm of (5,12) is 169
Example 2:-
CPP
// C++ program to demonstrate// example of norm() function.#include <bits/stdc++.h>using namespace std;// driver functionint main (){// initializing the complex: (4.0+3.0i)complex<double> complexnumber (4.0, 3.0);// use of norm()functioncout << "The norm of " << complexnumber << " is ";cout << norm(complexnumber) << endl;return 0;} |
Output:
The norm of (4,3) is 25


Please Login to comment...