Q:

Modify the program in Exercise 13 so that the function to calculate the angle is a subfunction to the function that prints

0

Modify the program in Exercise 13 so that the function to calculate the angle is a subfunction to the function that prints.

All Answers

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

Ch6Ex14.m

% Script calls functions to:

% prompt for an angle in degrees

% print degrees and radians, calling a

% subfunction to convert to radians

deg = promptAng;

prtDegRadii(deg)

promptAng.m

function deg = promptAng

% Prompts for an angle in degrees

% Format of call: promptAng or promptAng()

% Returns an angle in degrees

deg = input('Enter an angle in degrees: ');

end

prtDegRadii.m

function prtDegRadii(deg)

% Prints an angle in degrees and radians

% Calls a subfunction to convert to radians

% Format of call: prtDegRadii(degrees)

% Does not return any values

rad = degRadii(deg);

fprintf('The angle %.1f degrees is \n', deg)

fprintf('equivalent to %.1f radians\n', rad)

end

function rad = degRadii(deg)

% Converts an angle from degrees to radians

% Format of call degRadii(degrees)

% Returns the angle in radians

rad = deg * pi / 180;

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