Related Articles
Find the hypotenuse of a right angled triangle with given two sides
• Last Updated : 22 Apr, 2021

Given the other two sides of a right angled triangle, the task is to find it’s hypotenuse.
Examples:

Input: side1 = 3, side2 = 4
Output: 5.00
32 + 42 = 52
Input: side1 = 12, side2 = 15
Output: 19.21

Approach: Pythagoras theorem states that the square of hypotenuse of a right angled triangle is equal to the sum of squares of the other two sides.
Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach``#include``#include ``#include ``using` `namespace` `std;` `// Function to return the hypotenuse of the``// right angled triangle``double` `findHypotenuse(``double` `side1, ``double` `side2)``{``    ``double` `h = ``sqrt``((side1 * side1) + (side2 * side2));``    ``return` `h;``}` `// Driver code``int` `main()``{``    ``int` `side1 = 3, side2 = 4;``    ``cout << fixed << showpoint;``    ``cout << setprecision(2);``    ``cout << findHypotenuse(side1, side2);``}``    ` `// This code is contributed by``// Surendra_Gangwar`

## Java

 `// Java implementation of the approach``class` `GFG {` `    ``// Function to return the hypotenuse of the``    ``// right angled triangle``    ``static` `double` `findHypotenuse(``double` `side1, ``double` `side2)``    ``{``        ``double` `h = Math.sqrt((side1 * side1) + (side2 * side2));``        ``return` `h;``    ``}` `    ``// Driver code``    ``public` `static` `void` `main(String s[])``    ``{``        ``int` `side1 = ``3``, side2 = ``4``;``        ``System.out.printf(``"%.2f"``, findHypotenuse(side1, side2));``    ``}``}`

## Python3

 `# Python implementation of the approach` `# Function to return the hypotenuse of the``# right angled triangle``def` `findHypotenuse(side1, side2):` `    ``h ``=` `(((side1 ``*` `side1) ``+` `(side2 ``*` `side2))``*``*``(``1``/``2``));``    ``return` `h;` `# Driver code``side1 ``=` `3``;``side2 ``=` `4``;` `print``(findHypotenuse(side1, side2));` `# This code contributed by Rajput-Ji`

## C#

 `// C# implementation of the approach``using` `System;``    ` `class` `GFG``{` `    ``// Function to return the hypotenuse``    ``// of the right angled triangle``    ``static` `double` `findHypotenuse(``double` `side1,``                                 ``double` `side2)``    ``{``        ``double` `h = Math.Sqrt((side1 * side1) +``                             ``(side2 * side2));``        ``return` `h;``    ``}` `    ``// Driver code``    ``public` `static` `void` `Main()``    ``{``        ``int` `side1 = 3, side2 = 4;``        ``Console.Write(``"{0:F2}"``, findHypotenuse(side1,``                                               ``side2));``    ``}``}` `// This code is contributed``// by Princi Singh`

## Javascript

 ``
Output:
`5.00`

My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.571208,"math_prob":0.9517631,"size":2590,"snap":"2021-21-2021-25","text_gpt3_token_len":805,"char_repetition_ratio":0.18406805,"word_repetition_ratio":0.2748268,"special_character_ratio":0.31969112,"punctuation_ratio":0.15349887,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9984251,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-07T02:05:32Z\",\"WARC-Record-ID\":\"<urn:uuid:b1005e83-e432-4f65-b3ca-d831b1c6ae32>\",\"Content-Length\":\"110584\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e310ef2a-198d-4fc7-9dc1-aa7ff10ab7e0>\",\"WARC-Concurrent-To\":\"<urn:uuid:1ce15d18-0d86-40f1-a513-d015392b1a31>\",\"WARC-IP-Address\":\"23.15.9.35\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/find-the-hypotenuse-of-a-right-angled-triangle-with-given-two-sides/?ref=lbp\",\"WARC-Payload-Digest\":\"sha1:LC3OCUW4MVVE5QKETWW5G2RNBXDFMQIA\",\"WARC-Block-Digest\":\"sha1:YDXGZB2ZC2SC5SMG6R3CKUJ74KM7J5J7\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243988774.18_warc_CC-MAIN-20210506235514-20210507025514-00238.warc.gz\"}"}