garryhtreez

6.19

Dec 9th, 2020
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. /*
  2.     6.19 Hypotenuse Calculations
  3.     Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  4.     Visual Studio Community 2019
  5. */
  6.  
  7. #include <iostream>
  8. #include <cmath>
  9.  
  10. using namespace std;
  11.  
  12. double hypotenuse(double side1, double side2) {
  13.     double hypotenuse{ 0.0 };
  14.     hypotenuse = sqrt( side1 * side1 + side2 * side2 );
  15.     return hypotenuse;
  16. }
  17.  
  18. int main()
  19. {
  20.     double sideA = 3.0, sideB = 4.0;
  21.     cout << "For sides " << sideA << " and " << sideB << " the hypotenuse equals: " << hypotenuse(sideA, sideB) << endl;
  22.     sideA = 5.0, sideB = 12.0;
  23.     cout << "For sides " << sideA << " and " << sideB << " the hypotenuse equals: " << hypotenuse(sideA, sideB) << endl;
  24.     sideA = 8.0, sideB = 15.0;
  25.     cout << "For sides " << sideA << " and " << sideB << " the hypotenuse equals: " << hypotenuse(sideA, sideB) << endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment