A pair of positive integers x and y is pythagorean if x2 + y2 is a perfect square. For example, the pair 3 and 4 is a pythagorean pair because 32 = 42 = 9 + 16 = 25, and 25 is a perfect square since 25 = 52.

Write a program that displays all pythagorean pairs x and y, where x < 50 and y < 50. Also show, for each such pair, sqrt(x2 + y2).

(Note. You can tell whether a number is a prefect square by taking its square root, rounding it to the nearest integer, and checking whether the square of the rounded square root is the same as the starting number. Here are definitions of two functions: issqrt(n) is the closest integer to the square root of n, and isPerfectSquare(n) yields true if n is a perfect square. Library function real(n) convert integer n to a real number and round(x) rounds to the nearest integer. Add these to your program.

Define
  isqrt(n: Integer): Integer by

  isqrt(n) = round(sqrt(real(n)))
%Define

Define
  isPerfectSquare(n: Integer): Boolean by

  isPerfectSquare(n) = result |
    Let s: Integer      = isqrt(n).
    Let result: Boolean = (s*s == n).
%Define

 

    [Language: Cinnameg  Kind: program]