Question: Using a shell prompt in Unix/Linux write a shell script that given two sides of a right triangle, calculates the hypotenuse. The formula for this
Using a shell prompt in Unix/Linux write a shell script that given two sides of a right triangle, calculates the hypotenuse. The formula for this is hyp2=A2+B2 Or hyp = (A2+B2)1/2. Your program should allow the user to enter the values for A and B, perform the calculation(s), and then print the output. The output should be a triangle that is labeled appropriately.
Here are some hints for writing the program.
Do the calculations in a couple of steps instead of trying to do them all at once. That is, first multiply A*A, then B*B, then add them together, then do the square root. Check your work at each step by printing the intermediate results.
Use the bc command to do the square root calculation. It has a sqrt function that can be called with sqrt($var).
Use the | + - and \ characters to print a triangle for the output. It can always be the same triangle, you just change the numbers.
Use the scale command to limit the number of decimal points for the hypotenuse, but do at least two places after the decimal.
You can assume that the user will enter numbers, so you dont have to do any error checking of the input.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
