Introduction to MATLAB 3rd Edition ISBN13 9780133770018 Chap
Introduction to MATLAB (3rd Edition) (ISBN-13 978-0-13-377001-8) Chapter 4, Problem #3.
Solution
Code:
len = input(\'Enter the length of the base: \');
lenM = input(\'Is that i or c? :\',\'s\');
width = input(\'Enter the width of the base: :\');
widthM = input(\'Is that i or c? :\',\'s\');
height = input(\'Enter the height: :\');
heightM = input(\'Is that i or c? :\',\'s\');
if(eq(lenM,\'c\'))
len = len*2.54;
end
if(eq(widthM,\'c\'))
width = width*2.54;
end
if(eq(heightM,\'c\'))
height = height*2.54;
end
base = width*len;
volume = 1/3*base*height;
fprintf(\'The volume of the pyramid is %d cubic inches.\ \',volume);
Output:
Enter the length of the base: 50
Is that i or c? :i
Enter the width of the base: :6
Is that i or c? :c
Enter the height: :4
Is that i or c? :i
The volume of the pyramid is 1016 cubic inches
