informaticage

C++ Pythagorean Theorem

Oct 22nd, 2020 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. int main () {
  5.     using namespace std;
  6.  
  7.     double cathetus_1, cathetus_2;
  8.     cout << "Inserire cateto 1 e cateto 2: ";
  9.     cin >> cathetus_1 >> cathetus_2;
  10.    
  11.     double hypotenuse;
  12.     // Method 1
  13.     // Applying the Pythagorean theorem
  14.     hypotenuse = sqrt (
  15.         ( cathetus_1 * cathetus_1 )
  16.         + ( cathetus_2 * cathetus_2 ) );
  17.    
  18.     // Method 2
  19.     // Applying the Pythagorean theorem
  20.     hypotenuse = sqrt (
  21.         pow ( cathetus_1, 2 )  
  22.         + pow ( cathetus_2, 2 ) );
  23.  
  24.     // Method 3
  25.     // Applying the Pythagorean theorem
  26.     hypotenuse = hypot ( cathetus_1, cathetus_2 );
  27.  
  28.     cout << hypotenuse << endl;
  29.  
  30.     return 0;  
  31. }
Add Comment
Please, Sign In to add comment