C hypot Function

The hypot function is a C programming Math Function, used to calculate the Trigonometric Hypotenuse Value of given two sides. The syntax of the hypot is as shown below.

double hypot(double number);

Hypothenuse = square root of the sum of squares of two sides (specified arguments).

hypot Function Example

The math hypot Function allows you to find the Hypotenuse Value of a given side. In this program, We are going to find the hypotenuse and display the output.

/* Example for HYPOT */

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

int main()
{
printf("\n The Hypotenuse Value of 10 & 0 = %.4f ", hypot(10, 0));
printf("\n The Hypotenuse Value of 0 & -5 = %.4f ", hypot(0, -5));

printf("\n The Hypotenuse Value of 5 & -2 = %.4f ", hypot(5, -2));
printf("\n The Hypotenuse Value of -2 & 10 = %.4f ", hypot(-2, 10));

printf("\n The Hypotenuse Value of 10 & 12 = %.4f ", hypot(10, 12));
printf("\n The Hypotenuse Value of 5 & 20 = %.4f ", hypot(5, 20));

return 0;
}
 The Hypotenuse Value of 10 & 0  = 10.0000 
 The Hypotenuse Value of 0 & -5  = 5.0000 
 The Hypotenuse Value of 5 & -2  = 5.3852 
 The Hypotenuse Value of -2 & 10 = 10.1980 
 The Hypotenuse Value of 10 & 12 = 15.6205 
 The Hypotenuse Value of 5 & 20  = 20.6155

math hypot Example 2

In this C Programming example, we are allowing the user to enter the two sides of a triangle. Next, we used the math hypot function to find the hypotenuse of a user given side.

/* Example for HYPOT */

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

int main()
{
int side1, side2;
float hValue;

printf(" Please Enter the First and Second Side : ");
scanf("%d%d", &side1, &side2);

hValue = hypot(side1, side2);

printf("\n The Hypotenuse Value of %d & %d = %.4f ", side1, side2, hValue);

return 0;
}
C hypot Function Example