The area A of a rhombus is defined as A = d1d2 /2, where d1 and d2 are the lengths of the two diagonals. Write a script rhomb that first prompts the user for the lengths of the two diagonals
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:4| Question number:8.4
All Answers
total answers (1)
rhomb.m
% Prompt the user for the two diagonals of a rhombus,
% call a function to calculate the area, and print it
d1 = input('Enter the first diagonal: ');
d2 = input('Enter the second diagonal: ');
if d1 <= 0 || d2 <= 0
disp('Error in diagonal')
else
rharea = rhombarea(d1,d2);
fprintf('The area of the rhombus is %.2f\n', rharea)
end
rhombarea.m
function rarea = rhombarea(d1,d2)
% Calculates the area of a rhombus given the
% lengths of the two diagonals
% Format of call: rhombarea(diag1, diag2)
% Returns the area of the rhombus
rarea = (d1*d2)/2;
end
need an explanation for this answer? contact us directly to get an explanation for this answer