PLEASE ONLY ATTEMPT IF YOU ARE SURE! Write a MATLAB script file hw04-6.m that pr
ID: 3755331 • Letter: P
Question
PLEASE ONLY ATTEMPT IF YOU ARE SURE!
Write a MATLAB script file hw04-6.m that prompts for the user's input of the length I and the width w of a rectangle, and then outputs on the screen the area and the perimeter of the rectangle. The input and the output screens look like, for l- 12, and w 15 INPUT SCREEN: Give length (in mm): 12 Give width (in mm) 15 OUTPUT SCREEN: The area of a rectangle with length 12 mm and width 15 mm 180 sq. mm The perimeter of a rectangle with sides 12 mm and 15 mm- 54 mmExplanation / Answer
MATLAB Program:
#user input part
length = input('Give length(in mm): ');
width = input('Give width(in mm): ');
#calculation part
a = length*width;
p = 2*(length+width);
#displaying outputs
fprintf(' The area of a rectangle with length %d mm and width %d mm = %.2f sq.mm',length,width,a);
fprintf(' The perimeter of a rectangle with sides %d mm and %d mm = %.2f mm',length,width,p);
Output:
Give length(in mm) 12
Give width (in mm):15
The are of a rectangle with length 12 mm and width 15mm = 180 sq.mm
The perimeter of a rectangle with sides 12 mm and 15 mm = 54mm
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.