English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have an assignment and i got stuck on this question.... please help me if you can.... all what's required is a small pseudocode for the problem....

Write an algorithm that computes the length of the third side of a right triangle given the lengths of the other two sides.

Input: x,y (the lengths of two sides), and w (if w = 0, x and y are the legs; if w = 1, either x or y is the hypotenuse)
Output: z (the length of the third side)

2007-09-26 15:39:02 · 2 answers · asked by abdul a 2 in Science & Mathematics Mathematics

2 answers

input x
input y
input w

if w = 0 then
third_length = sqrt(x^2 + y^2)

if w = 1 then
if x third_length = sqrt(x^2 - y^2)

print third_length

end

swap routine
{swap x, y}
t = x
x = y
y = t
return


==== In Microsoft Excel

x value in cell A1
y value in cell A2
w value in cell A3

Value of Third Length
=IF(A3=0, SQRT(A1^2+A2^2), SQRT(ABS(A1^2-A2^2)))

2007-09-26 15:51:18 · answer #1 · answered by ideaquest 7 · 0 0

if w = 0 then

z = sqrt(x*x + y*y)

else

if w = 1 then

z = abs[sqrt(x*x - y*y)]

-------------------------------------------------------------------

sqrt = "square root of"; abs = "absolute value of"

The formula for a right triangle is a^2 + b^2 = c^2, where a and b are the legs.

[if w is 1 let z be the absolute value of the square root of x squared - y squared, since you don't know if x is greater than y.]

2007-09-26 22:44:01 · answer #2 · answered by SoulDawg 4 UGA 6 · 0 0

fedest.com, questions and answers