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

조회 수: 7 (최근 30일)
Ashley Sullivan
Ashley Sullivan 2020년 3월 11일
댓글: Rena Berman 2020년 5월 14일
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

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by