Q:

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

0

 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. If either is a negative number or zero, the script prints an error message. Otherwise, if they are both positive, it calls a function rhombarea to return the area of the rhombus, and prints the result. Write the function, also! The lengths of the diagonals, which you can assume are in inches, are passed to the rhombarea function. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now