Write a complete C++ program that meets the following criteria: · Use the Pythag
ID: 3629089 • Letter: W
Question
Write a complete C++ program that meets the following criteria:
· Use the Pythagorean theorem to calculate the length of the hypotenuse of a right triangle given the two sides. (hypotenuse = sqrt( side12 + side22 ) )
· The length of side1 should range from 1 to and including 10 incrementing by 1.
· The length of side2 should be twice the length of side1.
· You must use a for loop for this program.
· Declare all variables you use to be the appropriate type.
· There is no cin in this program!
· Display the value of the hypotenuse with 3 digits after the decimal point.
· Each line of output should contain the value of side1, side2, and the hypotenuse. An example of the output is shown below.
Side1 = 1, Side2 = 2, Hypotenuse = 2.236 (from first pass thru loop)
Side1 = 2, Side2 = 4, Hypotenuse = 4.472 (from second pass thru loop)
Explanation / Answer
please rate - thanks
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{int side1,side2;
double hyp;
for(side1=1;side1<=10;side1++)
{side2=side1*2;
hyp=sqrt(side1*side1+side2*side2);
cout<<"Side1 = "<<side1<<", Side2 = "<<side2
<<", Hypotenuse = "<<setprecision(3)<<fixed<<hyp<<endl;
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.