Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script file Ask the user to enter sides of a triangle: a, b, c Check to

ID: 3789504 • Letter: W

Question

Write a script file Ask the user to enter sides of a triangle: a, b, c Check to see if the sides are all greater than 0 If they are: Use the function (triangle) that you created in your last homework problem (HW#5 problemttF) to calculate the area. command Display the results on the screen using fprintf write the results to disk using the fprintf command. If any of the sides triangle are zero or negative: display an error message. of the Print your m-file & the file written to disk. Please test & show results for sides 6, 8, 10

Explanation / Answer

% matlab code

function area = traingle(a,b,c)
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
end

a = input("Enter side1 of traingle: ");
b = input("Enter side2 of traingle: ");
c = input("Enter sidec of traingle: ");

if(a > 0 && b > 0 && c >0)
area = traingle(a,b,c);
fprintf("Area: %f ",area);
else
disp("Invalid sides ");
end

%{
output:
Enter side1 of traingle: 6
Enter side2 of traingle: 8
Enter sidec of traingle: 10
Area: 24.000000


Enter side1 of traingle: -1
Enter side2 of traingle: 3
Enter sidec of traingle: 2
Invalid sides
%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote