Froborr d'Wiggy (froborr) wrote,
Froborr d'Wiggy
froborr

Can somebody check my logic?

It's been years since I've done anything programmy. This isn't meant to be in any particular programming language. Just assume "int xxxx(int A, int B)" defines a function xxxx that takes two integers and returns one.

Would the following "program" determine the Pythagorean triplet {A,B,C} (i.e., a trio of natural numbers that could satisfy the Pythagorean theorem) such that A+B+C=1000?

{
A == 1
B == 1
display A
display B
display Pythag(A,B)
}

int Pythag(int A, int B) {
C == 1000 – A – B
if (sqrt(A^2+B^2)=C^2) {
return C
else {
B++
if (1000 – A – B < 1) {
A++
B == 1
}
Return Pythag(A,B)
}
}
}
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 3 comments