Write a program that computes the area of a triangle using Heron’s formula. Prompt the user for the lengths of the three sides, say a, b, and c. Heron’s formula is: Area = sqrt(s(s − a)(s − b)(s − c)), where s = (a+b+c) / 2 , the semi-perimeter. 1. Create code to input the three values, a, b, and c which are the sides of the triangle. 2. Create two variables, one for area and one for semi-perimeter. 3. Compute the semi-perimeter and the quantity under the radical. 4. If the area squared is negative or zero you do not have a triangle. Output the appropriate message. 5. If the area squared is positive you have a triangle. 6. Test your program with these values for (a, b, c): (5, 7, 9), (6.2, 3.7, 4.5), (15, 11, 8.1), (8, 15, 17), (6, 15, 8) and another triple of your choice. • The output should look like the one of following: The triangle with sides: #1, #2, #3 is not a triangle The triangle with sides: #1, #2, #3 has semi-perimeter: #p and area: #a Note: The program should avoid trying to compute the square root of a negative number. (Your program has to check negative square roots) |
|
|
|
|