102k views
1 vote
Using a function file, create a function that will compute the area and perimeter of a square given the length of the side. The input variable will be the length and the output will be the area and the perimeter. Use an input command in the script file to ask the user to enter the length in inches, then use the function to compute the values and in the script file print the values to the screen. Repeat this until the user decides to quit For testing purposes please use the following inputs for the file you submit: Testing Conditions Length 5 in Length 10 in Length 7.5 in

User Alex White
by
5.3k points

1 Answer

4 votes

Answer:

Using Matlab, the code is here

function p = Sq(side)

a = side*side;

p = 4*side;

fprintf("The area of square is %.2f\\",a);

fprintf("The perimeter of square is %.2f\\",p);

end

while true

side = input("Enter the side of square: ");

Sq(side);

c = input("Do you wish to continue (Y/N) ?", 's');

if c=='n' || c=='N'

break;

end

User FrancescoMM
by
4.9k points