where is my fault ?

1 view (last 30 days)
Irem Deniz
Irem Deniz on 22 Jan 2021
Commented: Mathieu NOE on 25 Jan 2021
this is not an exam question or homework. This is an image from the quiz I entered this morning. I could not do the question, I'm still struggling
function volume_hprism(a,n)
hh=input("Enter the height of prism:");
h=1:hh;
a=2;
n=3;
V=7/4*a*n*h;
table=[h;V]';
disp("Volume of a heptagonal prism with a side lenght 2 and an apothem lenght 1.5 m.");
disp("Height(m) V(m^3)")
fprintf("%3.0f\t%10.4f\n",table)
endfunction

Accepted Answer

Mathieu NOE
Mathieu NOE on 22 Jan 2021
hello
you were almost there - just split the code in main section and 2 sub functions
%% main code %%
hh=input("Enter the height of prism:");
a=2;
n=3;
disp_table_hprism(a,n,hh) % call to first sub function
%% sub functions %%
function disp_table_hprism(a,n,hh)
h=1:hh;
V= volume_hprism(a,n,h); % call to second sub function
table=[h;V]';
disp("Volume of a heptagonal prism with a side lenght 2 and an apothem lenght 1.5 m.");
disp("Height(m) V(m^3)")
fprintf("%3.0f\t%10.4f\n",table)
end
function V= volume_hprism(a,n,h)
V=7/4*a*n*h;
end
  2 Comments
Irem Deniz
Irem Deniz on 24 Jan 2021
thank u very much
Mathieu NOE
Mathieu NOE on 25 Jan 2021
you're welcome
would you accept my answer ? tx

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!