(Pythagorean Triples) A right triangle can have sides that areall integers. A se
ID: 3616203 • Letter: #
Question
(Pythagorean Triples) A right triangle can have sides that areall integers. A set of there integer values for the sides of aright triangle 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. Its not working output because not right number. what wrongsomething my code?#include <iostream>
using namespace std;
int main()
{
int side1 = 0;
int side2 = 0;
int hypotenuse = 0;
for( int side1 = 0; side1 <= 500; side1++)
{
if((side1*side1)+(side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*" <<side1 << "+" << side2 << "*" << side2<< "=" << hypotenuse << "*" << hypotenuse<< endl;
}
for( int side2 = 1; side2 <= 500; side2++)
{
if( (side1*side1)+( side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*" <<side1 << "+" << side2 << "*" << side2<< "=" << hypotenuse << "*" << hypotenuse<< endl;
}
for(int hypotenuse = 0; hypotenuse <=500; hypotenuse++)
{
if( (side1*side1)+( side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*"<< side1 << "+" << side2 << "*" <<side2 << "=" << hypotenuse << "*" <<hypotenuse << endl;
cout << "The number of triples: "<<hypotenuse<<endl;
}
}
}
}
return 0;
} (Pythagorean Triples) A right triangle can have sides that areall integers. A set of there integer values for the sides of aright triangle 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. Its not working output because not right number. what wrongsomething my code?
#include <iostream>
using namespace std;
int main()
{
int side1 = 0;
int side2 = 0;
int hypotenuse = 0;
for( int side1 = 0; side1 <= 500; side1++)
{
if((side1*side1)+(side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*" <<side1 << "+" << side2 << "*" << side2<< "=" << hypotenuse << "*" << hypotenuse<< endl;
}
for( int side2 = 1; side2 <= 500; side2++)
{
if( (side1*side1)+( side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*" <<side1 << "+" << side2 << "*" << side2<< "=" << hypotenuse << "*" << hypotenuse<< endl;
}
for(int hypotenuse = 0; hypotenuse <=500; hypotenuse++)
{
if( (side1*side1)+( side2*side2)==(hypotenuse*hypotenuse))
{
cout << side1 << "*"<< side1 << "+" << side2 << "*" <<side2 << "=" << hypotenuse << "*" <<hypotenuse << endl;
cout << "The number of triples: "<<hypotenuse<<endl;
}
}
}
}
return 0;
}
Explanation / Answer
please rate - thanks #include using namespace std; int main() { int side1 = 0; int side2 = 0; int hypotenuse = 0; int count=0; for(side1 = 1; side1Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.