Q:

The script circscript loops n times to prompt the user for the circumference of a circle (where n is a random integer). Error-checking is ignored to focus on functions in this program

0

 The script circscript loops n times to prompt the user for the circumference of a circle (where n is a random integer). Error-checking is ignored to focus on functions in this program. For each, it calls one function to calculate the radius and area of that circle, and then calls another function to print these values. The formulas are r = c/(2Π) and a = Π r2 where r is the radius, c is the circumference, and a is the area. Write the two functions.

All Answers

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

circscript.m

n = randi(4);

for i = 1:n

 circ = input('Enter the circumference of the circle: ');

 [rad, area] = radarea(circ);

 dispra(rad,area)

end

radarea.m

function [radius, area] = radarea(circ)

% Calculates the radius and area of a circle,

% given the circumference

% Format of call: radarea(circumference)

% Returns the radius then area

radius = circ/(2*pi);

area = pi * radius ^2;

end

dispra.m

function dispra(radius, area)

% Prints the radius and area of a circle

% Format of call: dispra(radius, area)

% Does not return any values

fprintf('The radius of the circle is %.2f\n', radius)

fprintf('The area of the circle is %.2f\n', area)

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