Now that we have relational operators and
if statements, let’s start writing the program.
Here are the steps we will follow to develop the program incrementally:
- Write a script named findtriples.m and start with a loop that enumerates values of
aand displays them.
- Write a second loop that enumerates values of
band a third loop that enumerates values of
- Use the if statement from the previous section to check whether
cform a Pythagorean triple.
- Display the values that pass the test.
- Transform the script into a function and make it take an input variable that specifies the range to search.
Along the way, we’ll optimize the program to eliminate unnecessary work.