Question: // Find Pythagorean triples using brute force computing. #include using std::cout; using std::endl; int main() { int count = 0; // number of triples found
// Find Pythagorean triples using brute force computing. #includeusing std::cout; using std::endl; int main() { int count = 0; // number of triples found long int hypotenuseSquared; // hypotenuse squared long int sidesSquared; // sum of squares of sides cout << "Side 1\tSide 2\tSide3" << endl; // side1 values range from 1 to 500 /* Write a for header for side1 */ { // side2 values range from current side1 to 500 /* Write a for header for side2 */ { // hypotenuse values range from current side2 to 500 /* Write a for header for hypotenuse */ { // calculate square of hypotenuse value /* Write a statement to calculate hypotenuseSquared */ // calculate sum of squares of sides /* Write a statement to calculate the sum of the sides Squared */ // if (hypotenuse)^2 = (side1)^2 + (side2)^2, // Pythagorean triple if ( hypotenuseSquared == sidesSquared ) { // display triple cout << side1 << '\t' << side2 << '\t' << hypotenuse << ' '; count++; // update count } // end if } // end for } // end for } // end for // display total number of triples found cout << "A total of " << count << " triples were found." << endl; return 0; // indicate successful termination } // end main
If I were able to write these as three seperate values, this wouldn't be an issue. Given the instructions, side2 must be the current side1, and hypontenuse must be the current side2.
I don't understand how to approach this.
Example of what I tried to do with side2 and hypontenuse:
for (side2 = 1; side2 <= 500; side2++)
{
hypotenuse = side2;
for (hypotenuse; hypotenuse <= 500;)
But I imagine this is wrong, but I have no clue.
Anything help would be appreciated. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
