Таблица сложения...
+ 2 3
2 4 5
3 5 6
В заранее огромное спасибо.
делаю так . но резульат неверный.
Код:
print "<table border=1 cellpadding = 5>\n";
for($y=1; $y < 10; $y++)
{
print "<tr>\n";
for($x=1; $x < 10; $x++)
{
if($x == 1 and $y == 1)
{
print "\t<td>";
print "+";
print "</td>\n";
}
else
{
print "\t<td>";
print ($x+$y);
print "</td>\n";}
}
print "</tr>\n";
}
print "</table>";
for($y=1; $y < 10; $y++)
{
print "<tr>\n";
for($x=1; $x < 10; $x++)
{
if($x == 1 and $y == 1)
{
print "\t<td>";
print "+";
print "</td>\n";
}
else
{
print "\t<td>";
print ($x+$y);
print "</td>\n";}
}
print "</tr>\n";
}
print "</table>";
Код:
print "<table border=1 cellpadding = 5>\n";
for($y=1; $y < 11; $y++)
{
print "<tr>\n";
for($x=1; $x < 11; $x++)
{
if($x == 1 and $y == 1)
print "\t<td>+</td>\n";
else
{
if($x!=1 and $y!=1)
print "\t<td>".($x+$y)."</td>\n";
else
print "\t<td>".($x==1?$y:$x)."</td>\n";
}
}
print "</tr>\n";
}
print "</table>";
for($y=1; $y < 11; $y++)
{
print "<tr>\n";
for($x=1; $x < 11; $x++)
{
if($x == 1 and $y == 1)
print "\t<td>+</td>\n";
else
{
if($x!=1 and $y!=1)
print "\t<td>".($x+$y)."</td>\n";
else
print "\t<td>".($x==1?$y:$x)."</td>\n";
}
}
print "</tr>\n";
}
print "</table>";
Както так
Спасибо.. работает:)
Код:
define("ROW_X_MIN", 2); // кол-во по X - нач.знача
define("ROW_X_MAX", 10); // кол-во по X - кон.знач
define("ROW_Y_MIN", 2); // кол по Y -//-
define("ROW_Y_MAX", 10);
# здесь вывод первой строки
# вывод значений таблицы
for( $curr_y = ROW_Y_MIN; $curr_y <= ROW_Y_MAX; ++$curr_y ) {
echo("<tr><td>{$curr_y}</td>");
for($curr_x = ROW_X_MIN; $curr_x <= ROW_X_MAX; ++$curr_x) {
echo("<td>".($curr_x + $curr_y)."</td>");
}
echo("</tr>");
}
define("ROW_X_MAX", 10); // кол-во по X - кон.знач
define("ROW_Y_MIN", 2); // кол по Y -//-
define("ROW_Y_MAX", 10);
# здесь вывод первой строки
# вывод значений таблицы
for( $curr_y = ROW_Y_MIN; $curr_y <= ROW_Y_MAX; ++$curr_y ) {
echo("<tr><td>{$curr_y}</td>");
for($curr_x = ROW_X_MIN; $curr_x <= ROW_X_MAX; ++$curr_x) {
echo("<td>".($curr_x + $curr_y)."</td>");
}
echo("</tr>");
}
Вот, как-то так. Код на корректность не проверял
Код:
?>
<tbody><tr>
<td>+</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>3</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td>4</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>5</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
<tr>
<td>6</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
</tr>
<tr>
<td>7</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
</tr>
<tr>
<td>8</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
<tr>
<td>9</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
</tr>
<tr>
<td>10</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
</tr>
</tbody>
<?php
<tbody><tr>
<td>+</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
</tr>
<tr>
<td>2</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td>3</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
<tr>
<td>4</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>5</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
</tr>
<tr>
<td>6</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
</tr>
<tr>
<td>7</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
</tr>
<tr>
<td>8</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
<tr>
<td>9</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
</tr>
<tr>
<td>10</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
</tr>
</tbody>
<?php