This commit is contained in:
3p01
2025-12-04 09:30:07 +01:00
parent bdbd6c2386
commit 7b5fbb9d8b
4 changed files with 428 additions and 39 deletions

View File

@@ -42,39 +42,39 @@
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = htmlspecialchars($_POST['n']);
(int)$values = explode(',', htmlspecialchars($_POST['values']));
echo '<div class="box">';
$nInput = htmlspecialchars($_POST['n']);
$valuesInput = htmlspecialchars($_POST['values']);
$isValidDimensions = is_numeric($nInput) && (int)$nInput == $nInput && (int)$nInput > 0 && (int)$nInput <= 100;
$n = (int)$nInput;
$values = array_map('trim', explode(',', $valuesInput));
$count = count($values);
$isCountValid = $count === $n;
$areAllValuesValid = true;
if (count($values) != $n) {
echo "Liczba elementów n = $n<br>";
echo '<div class="box">';
for ($i = 0; $i < $count; $i++) {
if (!is_numeric($values[$i])) {
$areAllValuesValid = false;
} else {
$values[$i] = (float)$values[$i];
}
}
if ($isValidDimensions && $isCountValid && $areAllValuesValid) {
echo "Wymiar tablicy: n = $n<br>";
echo "Wprowadzone liczby: ";
echo implode(', ', $values);
echo "<br>Rezultat: Liczba wprowadzony wartości (".count($values).") nie zgadza się z n ($n)";
return;
}
for ($i = 0; $i < $n; $i++) {
if (!is_numeric($values[$i]) || !is_int($values[$i])) { $areAllValuesValid = false; }
$values[$i] = (int)$values[$i];
}
if ($areAllValuesValid && $n <= 100 && count($values) == $n) {
echo "Wymiar tablicy: n = $n<br>";
echo "Wprowadzone liczbe: ";
echo implode(', ', $values);
echo "<br>Tablica:";
echo '<table>';
echo '<tr>';
for ($i = 0; $i < $n; $i++) {
for ($i = 0; $i < $count; $i++) {
echo '<td>' . $values[$i] . '</td>';
}
echo '</tr>';
echo '</table>';
} else {
echo 'Dane wejściowe nie są poprawne! Sprawdź wymiar, liczbę wartości lub czy wszystkie są liczbami.';
}
else {
echo 'Liczby nie są poprawne!';
}
echo '</div>';
}
?>
</body>