C hypot()

hypot() function Prototype

double hypot(double p, double b);

h = √(p2+b2) in mathematics is equivalent to h = hypot(p, b); in C Programming.


The hypot() function is defined in math.h header file.


Example: C hypot() Function

#include <stdio.h>
#include <math.h>

int main()
{
    double p, b;
    double hypotenuse;

    p = 5.0;
    b = 12.0;

    hypotenuse = hypot(p, b);

    printf("hypot(%.2lf, %.2lf) = %.2lf", p, b, hypotenuse);

    return 0;
}

Output

hypot(5.00, 12.00) = 13.00

Before we wrap up, let’s put your knowledge of C math hypot() to the test! Can you solve the following challenge?

Challenge:

Write a function to calculate the hypotenuse of a right triangle.

  • Hint: The formula to compute the hypotenuse of the right triangle is {hypotenuse} = sqrt{{side1}^2 + {side2}^2}.
  • For example, with inputs side1 = 3 and side2 = 4, the return value should be 5.00.
Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges