Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

2.

a. areaofrectangle.m
Command Window:
>> areaofrectangle
Enter length of rectangle:5.34

length =

5.3400

Enter width of rectangle:4.56

width =

4.5600

area =

24.3504

24.35
Script:
%Prompt user to enter length
length = input('Enter length of rectangle:')
%Prompt user to enter width
width = input('Enter width of rectangle:')
%Prompt user to find are
area = length*width
%Allow user to print the area with 2 decimal places
fprintf('%3.2f \n',area)

b. translatethis.m
Command Window:
>> translatethis
Enter annual income 205000
Typical food expenditure is between $16400.00 to $20500.00 per year.

Script:
%Prompt user for annual income
annual = input('Enter annual income');
%Typical annual food expenditure assuming 8 to 10% of annual income is
%spent on food.
fprintf('Typical food expenditure is between $%.2f to $%.2f per
year.\n\n',.08*annual,.1*annual)

c. quadraticformula.m
Command Window:
>> quadraticformula
Enter value of a:2
Enter value of b:-10
Enter value of c:12
The value of x(1) is 3
The value of x(2) is 2
Script:
a = input('Enter value of a:');
b = input('Enter value of b:');
c = input('Enter value of c:');
x(1) = (-b + sqrt((b^2) - (4*a*c)))/(2*a);
x(2) = (-b - sqrt((b^2) - (4*a*c)))/(2*a);
fprintf('The value of x(1) is %.0f \n', x(1))
fprintf('The value of x(2) is %.0f \n', x(2))

d. temperature.m
Command Window:
>> temperature
Enter temperature value in Celsius:0

F=

32

The equivalent temperature in Fahrenheit is 32.00


>> temperature
Enter temperature value in Celsius:100

F=

212

The equivalent temperature in Fahrenheit is 212.00


>> temperature
Enter temperature value in Celsius:-40

F=

-40

The equivalent temperature in Fahrenheit is -40.00


>> temperature
Enter temperature value in Celsius:37

F=

98.6000

The equivalent temperature in Fahrenheit is 98.60

Script:
C = input('Enter temperature value in Celsius:');
F = (((9*C)/5)+32)
fprintf('The equivalent temperature in Fahrenheit is %.2f \n', F)

You might also like