Computing the hypotenuse of a right triangle Write a program in C++ to calculate
ID: 3802584 • Letter: C
Question
Computing the hypotenuse of a right triangle Write a program in C++ to calculate the hypotenuse of a right triangle. First, make the program draw a right triangle with sides a, b, c. Make the program take integer coefficients a, b from the user. Calculate the hypotenuse c using the following formula: c = Squareroot a^2 + b^2 a) Display the value of the hypotenuse c after calculation. b) Display the value of the hypotenuse c with 5 significant digits. c) Make the program create and fill out the following table with the value of c using 2 significant digits.Explanation / Answer
1.Make the program to draw right angle triangle
#include <iostream>
using namespace std;
int main()
{
//declare variable type int
int i,j;
//print triangle
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<endl;
}
}
2.take integer coeffients from user
#include <iostream>
using namespace std;
int main ()
{
float a;
cout << "Please enter the value of a side a: ";
cin >> a;
float b;
cout << "Please enter the value of a side b: ";
cin >> b;
}
3.
int main ()
{
double a,b,c;
cout << "Please enter the length a side a: "<<endl;
cin >> a;
cout << "Please enter the lengthof a side b: "<<endl;
cin >> b;
c=sqrt((a*a)+(b*b));
cout<<"The hypotenuse==" <<c;
return 0;
}
Please take care of indentation while running a program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.