Question: Using UNIX//LINUX: Write or modify a shell script that given two sides of a right triangle, calculates the hypotenuse. The formula for this is: hyp
Using UNIX//LINUX:
Write or modify 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 must meet the following specifications:
a. Your name must be included in comments at the top of the file
b. It must allow the user to enter the values for A and B, perform the calculation(s), and then print the output. 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)
c. The output should be a triangle that is labeled appropriately. * Use the | + - and \ characters to print a triangle for the output. It can always be the same triangle, just change the numbers. Do something similar to:
+ | \ | \ 3.34 | \ 5.74 | \ |_________\ 4.76
d. Use the scale command to limit the number of decimal points for the hypotenuse, but do at least two places after the decimal.
e. You can assume that the user will enter reasonable numbers, so you don't have to do any error checking of the input.
f. After the calculations are complete and the results displayed, the program must ask the user if they want to repeat the process. If the answer in the affirmative then the code must loop and repeat. If the user answers in the negative the code should exit.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
