You are on page 1of 1

Calculate the volume of a round cylinder with a radius of r meters and height of h

meters.
The formula is V=πr^2h

MATLAB Code: Write a function and name it as volume_func(r,h) and also, write
a main function such that user can type the value of r and h.
MATLAB CODE:
close all; clear all; clc;
r = input('Type the radius = ');
h = input('Type the height = ');
V = volume_func(r,h);
fprintf('The volume of a round cylinder with a radius of %4.2f and height of %4.2f
is %4.2f ', r, h, V);

function V = volume_func(r,h);
V = pi*(r^2)*h;
end

You might also like