User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Begin12. The legs of the right triangle \(a\) and \(b\) are given. Find its hypotenuse \(c\) and perimeter \(P\):
\(c = \sqrt{a^2 + b^2}, \quad P = a + b + c\).

Solution in Python 3:

import random
import math

a = random.randrange(1,100)
b = random.randrange(1,100)
#a = 3
#b = 4
print("Cathetus 1: ", a)
print("Cathetus 2: ", b)
c = math.sqrt(a**2 + b**2)
P = a + b + c
print("Hypotenuse: ", c)
print("Perimeter: ", P)

Solution in C++:

#include<iostream>
#include<cmath>
using namespace std;
int main(){
double a,b,c,p;
cout << "Enter the first leg: ";
cin >> a;
cout << "Enter the second leg: ";
cin >> b;
c = sqrt(pow(a,2)+pow(b,2));
p = a+b+c;
cout << "Hypotenuse: " << c << endl;
cout << "Perimeter: " << p << endl;
return 0;
}