The hypot() function in C++ returns the square root of sum of square of arguments passed. It finds the hypotenuse, hypotenuse is the longest side of a right angled triangle. It is calculated by the formula :
h = sqrt(x2+y2)
where x and y are the other two sides of the triangle.
Syntax: double hypot(double x, double y); float hypot(float x, float y); long double hypot(long double x, long double y);
Input : x=3, y=4 Output :5 Input :x=9, y=10 Output :13.4536
Header File : cmath
Parameters : The hypot() takes either 2 or 3 parameters of integral or floating-point type.
1. The hypotenuse of a right-angled triangle if two arguments are passed.
2. Distance from the origin to to the (x, y, x) if three arguments are passed
Exceptions or Errors
1. hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent.
2. If one of the arguments is 0, hypot(x, y) is equivalent to fabs called with the non-zero argument
3. If one of the arguments is infinite or undefined, hypot(x, y) returns undefined.
Example Application : Finding the hypotenuse of a right angle triangle given 2 of its other sides.
hypotf() function is same as the hypot function.The only difference is that the parameter and return type of the function is float type. The ‘f‘ character appended to ‘hypotf‘ stands for float and it signify the parameter type and return type of the function.
Syntax float hypotf(float x);
C++ program implementation of hypotf()
Here, variables are assigned float type otherwise type mismatch error occurs.
hypotl() function is same as the hypot function.The only difference is that the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘hypotl‘ stands for long double and it signify the parameter type and return type of the function.
Syntax long double hypotl(long double x);
C++ program implementation of hypotl()
Here, variables are assigned long double type otherwise type mismatch error occurs.
- C++ program to compare two Strings using Operator Overloading
- not1 and not2 function templates in C++ STL with Examples
- Go vs C++
- Trie Data Structure using smart pointer and OOP in C++
- std::hash class in C++ STL
- History of C++
- What are Forward declarations in C++
- __builtin_inf() functions of GCC compiler
- Structures in C++
- Variables in C++
- Implementing Forward Iterator in BST
- Count substrings that contain all vowels | SET 2
- Machine Learning in C++
- How can we use Comma operator in place of curly braces?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.