Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Algorithm Implementation/Mathematics/Pythagorean theorem

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

thumb|The Pythagorean theorem: The sum of the areas of the two squares on the legs (a and b) equals the area of the square on the hypotenuse (c). In mathematics, the Pythagorean theorem or Pythagoras' theorem is a relation in Euclidean geometry among the three sides of a right triangle (right-angled triangle). In terms of areas, it states: In any right triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:Roots to research: a vertical development of mathematical problems Judith D. Sally, Paul Sally 63 Chapter 3: Pythagorean triples http://books.google.com/books?id=nHxBw-WlECUC&pg=PA63 0821844032 2007 American Mathematical Society Bookstore where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides. Note: for most languages, a built-in hypot function performs the same calculation. This is for education only. Scheme (define (hypotenuse a b) (sqrt (+ (expt a 2) (expt b 2)))) ;; Equivalent, but does not check the number of arguments (define (hypotenuse . xs) (sqrt (fold (lambda (x acc) (+ (expt x 2) acc)) 0 xs))) Visual Basic Function Hypotenuse(sideA as Double, sideB as Double) as Double Hypotenuse = sqr(sideA^2 + sideB^2) End Function Java public static double hypotenuse(double sideA, double sideB) { double hypotenuse = Math.sqrt((sideA*sideA) + (sideB*sideB)); return hypotenuse; } Python def hypotenuse(a,b): return ( a**2 + b**2 )**.5 Haskell pythag a b = sqrt $ a^2 + b^2 Javascript const hypotenuse = (a,b) => Math.sqrt(a**2 + b**2) References