36: Build a program to calculate the hypotenuse of a right triangle
// Build a program to calculate the hypotenuse of a right triangle
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float base, perpendicular, hypotenuse;
cout << "Enter the base of the triangle: ";
cin >> base;
cout << "Enter the perpendicular of the triangle: ";
cin >> perpendicular;
hypotenuse = sqrt((pow(base, 2) + pow(perpendicular, 2)));
cout << "The hypotenuse of this triangle is: " << hypotenuse << endl;
return 0;
}
Or:
// Build a program to calculate the hypotenuse of a right triangle
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float base, perpendicular, hypotenuse;
cout << "Enter the base of the triangle: ";
cin >> base;
cout << "Enter the perpendicular of the triangle: ";
cin >> perpendicular;
hypotenuse = hypot(base, perpendicular);
cout << "The hypotenuse of this triangle is: " << hypotenuse << endl;
return 0;
}
Comments
Post a Comment