(Pythagorean Triples) A right triangle can have sides that are allintegers. A se
ID: 3616321 • Letter: #
Question
(Pythagorean Triples) A right triangle can have sides that are allintegers. A set of there integer values for the sides of a righttriangle is called a Pythagorean triple. There three sidesmus satisfy the relationship that the sum of the squares oftwo of the sides is equal to the square of teh hypotenuse. Find allpythagorean triples for side1, side2, and hypotenuse all no largerthan 500. Use a triple-nested for loop that tries al possibilities.This is an example of brute force computing. You'll learn in moreadvanced computer science courses that there are many interestingproblems for which there is no known algorithmic approach otherthan sheer brute force.
#include<iostream>
using namespace std;
int main()
{
int side1 = 0;
int side2 = 0;
int hypotenuse = 0;
int count=0;
for(side1 = 1; side1 <= 500; side1++)
{for(side2 = 1; side2 <= 500; side2++ )
{for(hypotenuse = 1; hypotenuse <= 500;hypotenuse++)
{
if( (side1*side1)+(side2*side2 )==(hypotenuse*hypotenuse))
{
cout << side1<< "*" << side1 << "+" << side2 <<"*" << side2 << "=" << hypotenuse << "*"<< hypotenuse << endl;
count++;
}
}
}
}
cout<<"There were "<<count<<"pythagorian triples found ";
system("pause");
return 0;
}