norm() function in C++ with Examples


In this article we will be discussing the working, syntax and examples of norm() function in C++ STL.

What is norm()?

norm() function is an inbuilt function in C++ STL, which is defined in <complex> header file. norm() function is used to get the norm value of a complex number.

Norm value of a complex number is the squared magnitude of a number. So in simple words the function finds the squared magnitude of a complex number, including its imaginary and real number.

Syntax

double norm(ArithmeticType num);

Parameters

The function accepts following parameter(s) −

  • num − The complex value which we want to work on.

Return value

This function returns a norm value of num.

Example

Input

complex<double> comp_num(6.9, 2.6);
norm(comp_num);

Output

The value of norm of (6.9,2.6) is 54.37

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main (){
   complex<double> comp_num(6.9, 2.6);
   cout<<"The value of norm of " << comp_num<< " is ";
   cout << norm(comp_num) << endl;
   return 0;
}

Output

The value of norm of (6.9,2.6) is 54.37

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main (){
   complex<double> comp_num(2.4, 1.9);
   cout<<"The value of norm of " << comp_num<< " is ";
   cout << norm(comp_num) << endl;
   return 0;
}

Example

The value of norm of (2.4,1.9) is 9.37

Updated on: 17-Apr-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements