Given a length of wire P units long, where P is an integer, it is possible in some cases to bend
the wire into an isosceles triangle(with two sides equal) where the lengths of all the sides are
also integers. For example a wire of length P = 3 units can be bent into an isosceles triangle,
while a wire of length P = 4 can not. For some lengths there is more than one isosceles
triangle with integer length sides. Of those isosceles triangles with integer length sides some
will have an area which is also an integer, while others will not.
The area of a triangle, given the lengths of its three sides a; b; c, is
Area =
where m = (a + b + c)=2.
(a) Write a function, which has as input an integer length P, and outputs(not prints) a
triple (a; b;A), where a is the integer length of the two equal length sides of an isosceles
triangle, b is the integer length of the other side, and A is the integer area of the
triangle. The function should output non-zero values (a; b;A) when there is ONLY
ONE isosceles triangle which has both integer length sides, and integer area,
otherwise it should return (0; 0; 0). Test your function with P = 15, where the output
should be (0; 0; 0) and P = 16, where the output should be (5; 6; 12).

This is what i've done at the moment, i get the right output for P = 15 but cannot get the right output for p = 16:

 function [a,b,A] = Funct1(p)

m = p/2;
n = fix(m);
for a = 1:n

    b = 2*a - p;
    p = 2*a+b;
    A = sqrt(m*((m - a)^2)*(m-b));
if (A~=fix(A))
    a = 0; b = 0; A = 0;

Thank You

Edited by peter_budo: Moving to legacy languages till established what language it this

5 Years
Discussion Span
Last Post by peter_budo
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.