# 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 ` `using` `namespace` `std;`   `// driver function` `int` `main ()` `{` `// initializing the complex: (5.0+12.0i)` `complex<``double``> complexnumber (5.0, 12.0);`   `// use of norm()function` `cout << ``"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 ` `using` `namespace` `std;`   `// driver function` `int` `main ()` `{` `// initializing the complex: (4.0+3.0i)` `complex<``double``> complexnumber (4.0, 3.0);`   `// use of norm()function` `cout << ``"The norm of "` `<< complexnumber << ``" is "``;` `cout << norm(complexnumber) << endl;`   `return` `0;` `}`

Output:

`The norm of (4,3) is 25`

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Previous
Next