C hypot Function

The C hypot function is a Math Function, used to calculate the Trigonometric Hypotenuse Value of given two sides. The syntax of the hypot in C Programming is

double hypot(double number);

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

C 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 in C Programming */

#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

C hypot Example 2

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

/* Example for HYPOT in C Programming */

#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 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.