Answers for "print matrix and color diagonally"

0

print matrix and color diagonally

$no=9;
echo "<center>";
echo "<table>";
for ($row=1; $row<=8 ; $row++) { 
	$no--; //to decrement
	echo "<tr>";
	for ($col=1; $col<=8; $col++) { 
		$color="";
		if ($row==$col) {
			$color = 'background-color:red';
		}
		if ($col==$no) { //col val == 8
			$color = 'background-color:green';	
		}
		echo "<td style=".$color.">".$row*$col."</td>";
	}
	echo "</tr>";
}
echo "</table>";
echo "</center>";
Posted by: Guest on October-13-2021
0

print matrix and color diagonally

$no=9;
echo "<center>";
echo "<table>";
for ($row=1; $row<=8 ; $row++) { 
	$no--;
	echo "<tr>";
	for ($col=1; $col<=8; $col++) { 
		$color="";
		if ($row==$col) {
			$color = 'background-color:red';
		}
		if ($col==$no) {
			$color = 'background-color:green';	
		}
		echo "<td style=".$color.">".$row*$col."</td>";
	}
	echo "</tr>";
}
echo "</table>";
echo "</center>";
Posted by: Guest on October-13-2021

Browse Popular Code Answers by Language