sub printMat {
#write the code for making and printing the matrix here
#use can use \n to move numers to next line in the matrix
#use " " to add space between numbers in matrix
#print "Write your code below"; #comment out this line when you start writing cod
for ($i = 0; $i < 4 ; $i++) {
for ($j = 0; $j < 4; $j++) {
if ($i==$j)
{
$val=0;
}
elsif($j<$i)
{
$val=-1;
}
else{
$val=1;
}
$comparisonAdjectives[$i][$j] = $val;
}
}
for ($i = 0; $i < 4 ; $i++) {
for ($j = 0; $j < 4; $j++) {
if ($comparisonAdjectives[$i][$j]>=0){
print " ".$comparisonAdjectives[$i][$j]." ";
}
else
{
print $comparisonAdjectives[$i][$j]." ";
}
}
print "\n";
}
}
printMat();
Thursday, October 20, 2022
matrix assignment in perl
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment