Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements