?

Log in

No account? Create an account
Froborr's Page of Stuffness

> recent entries
> calendar
> friends
> profile

Monday, August 25th, 2008
6:16a - 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)
}
}
}

(3 comments |comment on this)


<< previous day [calendar] next day >>
> top of page
LiveJournal.com