
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
abs() function for complex number in c++ ?
The abs function in C++ is used to find the absolute value of a complex number. The absolute value of a complex number (also known as modulus) is the distance of that number from the origin in the complex plane. This can be found using the formula −
For complex number a+bi:
mod|a+bi| = √(a2+b2)
The abs() function returns the result of the above calculation in C++. It is defined in the complex library that is needed to be included.
PROGRAM TO SHOW USE OF abs() FUNCTION FOR COMPLEX NUMBERS IN C++
#include <iostream> #include <complex> using namespace std; int main () { float a= 13.0 , b = 5.0; complex<double> complexnumber (a, b); cout << "The absolute value of " << a<<"+"<<b<<"i" << " is: "; cout << abs(complexnumber) << endl; return 0; }
Output
The absolute value of 13+5i is: 13.9284
- Related Articles
- arg() function for Complex Number in C++
- Cos() function for complex number in C++
- tanh( ) function for complex Number in C++
- log() function for complex number in C++
- log10() function for complex number in C++
- tan() function for complex number in C++
- pow() function for complex number in C++
- polar() function for complex number in C++
- exp() function for complex number in C++
- acos() function for complex number in C++?
- asin() function for complex number in C++?
- atan() function for complex number in C++?
- acosh() function for complex number in C++
- sqrt ( ) function for complex number in C++
- Sinh( ) function for complex number in C++

Advertisements