MATLAB Answers

area of a circle function file / prompt and fprintf() output

7 views (last 30 days)
Ashley Sullivan
Ashley Sullivan on 11 Mar 2020
Commented: Rena Berman on 14 May 2020 at 16:40
I have created a function file for the area of a circle, but I also need to include a prompt asking for the units of the radius. I also need to have the output area be expressed in the proper units, but am unsure of how to do either. This is what I have --
function [area] = area_circle(radius)
area = pi.*radius.^2;
end

  1 Comment

Sign in to comment.

Accepted Answer

Bhaskar R
Bhaskar R on 11 Mar 2020
function area_circle()
radius = input('Enter the radius: ');
area_cir = pi.*radius.^2;
disp(['Area of circle: ', num2str(area_cir)])
end

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by