% program cyl1 % S. Scott Moor September 2004 % calculates the surface area and volume of a right circular cylinder % uses interactive user input. % % r = radius % h = height (in the same units as r) % Vol = volume of the cylinder (in cubic units) % SA = surface area of the cylinder (in square units) % % This function can handle vector inputs. disp('This function calculates the volume and ') disp('surface area of a right circular cylinder') disp(' ') h = input('Enter the height of the cylinder in meters: '); r = input('Enter the diameter of the cylinder in meters: '); Vol = pi*r.^2.*h; SA = 2*pi*r.*h + 2*pi*r.^2; V = num2str(Vol); S = num2str(SA); disp(['Volume = ', V, ' cubic meters']) disp(['Surface Area = ',S, ' square meters'])