Definition:
In this question we define code that reads in three positive numbers representing the lengths of the sides of a triangle and prints out a message saying “it’s equilateral” if all three sides are of equal length.
Testing:
On paper, or in a text file, write three new tests for the above program. As an example, two tests for this program might be.
inputs output
5 5 5 “it’s equilateral”
2 1 2 <no output>
close all,
clear all,
clc,
sides = [
5,5,5;
2,1,2;
3,2,1;
3,4,5
];
for r=1:length(sides)
a=sides(r,1); b=sides(r,2); c = sides(r,3);
if (a==b && b==c && c==a)
disp(['<',num2str(sides(r,:)),'> it’s equilateral']);
else
disp(['<',num2str(sides(r,:)),'> no output']);
end
end
Matlab Output:
<5 5 5> it’s equilateral
<2 1 2> no output
<3 2 1> no output
<3 4 5> no output
>>
Comments
Leave a comment