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
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:6| Question number:18.6
All Answers
total answers (1)
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