0% found this document useful (0 votes)
18 views3 pages

Grupa A

Uploaded by

hamzasusnjar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Grupa A

Uploaded by

hamzasusnjar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

GRUPA A

<?php
define("TITLE", "TEST A");
$myName = "Admir Džaferović";
$lessonNum = 32;
?>

<!DOCTYPE html>
<html>

<head>
<title>PHP <?php echo TITLE; ?></title>
<link href="../assets/styles.css" rel="stylesheet">
<script type="text/javascript"
src="../assets/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript"
src="../assets/syntaxhighlighter/scripts/shBrushPhp.js"></script>
<link type="text/css" rel="stylesheet"
href="../assets/syntaxhighlighter/styles/shCoreDefault.css" />
<script type="text/javascript">
SyntaxHighlighter.all();
</script>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"

integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">
</head>

<body>
<div class="wrapper">
<a href="/" title="Back to directory" id="logo">
<img src="../assets/img/logo.png" alt="PHP" width="120px">
</a>

<h1>Primjer: <?php echo $lessonNum; ?>: <small><?php echo TITLE;


?></small></h1>
<hr>

<!-- Task 1 -->


<div class="sandbox">
<h3>1. Parni brojevi iz niza od 20 brojeva</h3>
<?php
$brojevi = range(1, 20);
$parni_brojevi = [];

foreach ($brojevi as $broj) {


if ($broj % 2 == 0) {
$parni_brojevi[] = $broj;
}
}

echo '<div class="alert alert-primary" role="alert">';


echo "<strong>Parni brojevi:</strong> ";
echo implode(", ", $parni_brojevi);
echo '</div>';
?>
</div>
<!-- Task 2 -->
<div class="sandbox">
<h3>2. Suma brojeva deljivih sa 3 i 7</h3>
<?php
$suma = 0;
foreach ($brojevi as $broj) {
if ($broj % 3 == 0 && $broj % 7 == 0) {
$suma += $broj;
}
}

echo '<div class="alert alert-info text-center" role="alert">';


echo "Suma brojeva deljivih sa 3 i 7 je: <strong>$suma</strong>";
echo '</div>';
?>
</div>

<!-- Task 3 -->


<div class="sandbox">
<h3>3. Gradovi iz USK-a</h3>
<?php
$gradovi = [
"Bihać", "Cazin", "Velika Kladuša", "Sanski Most", "Bosanska
Krupa",
"Sarajevo", "Zenica", "Tuzla", "Mostar", "Banja Luka"
];

echo '<ul class="list-group">';


foreach ($gradovi as $grad) {
if (in_array($grad, ["Bihać", "Cazin", "Velika Kladuša", "Sanski
Most", "Bosanska Krupa"])) {
echo "<li class='list-group-item list-group-item-danger text-
center'>$grad</li>";
}
}
echo '</ul>';
?>
</div>

<!-- Task 4 -->


<div class="sandbox">
<h3>4. Sortiranje unesenih imena</h3>
<form method="POST" action="">
<div class="input-group mb-3">
<input type="text" name="imena" class="form-control"
placeholder="Adis, Osman, Tarik, Ante, Kasim..." required>
<button class="btn btn-primary" type="submit">Sortiraj</button>
</div>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$imenaString = $_POST['imena'];
$imenaArray = array_map('trim', explode(",", $imenaString));
sort($imenaArray);

echo '<div class="alert alert-success" role="alert">';


echo "<strong>Sortirana imena:</strong> ";
echo implode(", ", $imenaArray);
echo '</div>';
}
?>
</div>

<!-- Task 5 -->


<div class="sandbox">
<h3>5. Izračunaj dimenzije pravougaonika</h3>
<form method="POST">
<div class="mb-3">
<label for="duzina" class="form-label">Dužina:</label>
<input type="number" name="duzina" step="any" class="form-
control" required>
</div>
<div class="mb-3">
<label for="sirina" class="form-label">Širina:</label>
<input type="number" name="sirina" step="any" class="form-
control" required>
</div>
<button type="submit" class="btn btn-primary">Izračunaj</button>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['duzina']) &&
isset($_POST['sirina'])) {
$duzina = $_POST['duzina'];
$sirina = $_POST['sirina'];

$povrsina = $duzina * $sirina;


$obim = 2 * ($duzina + $sirina);
$dijagonala = sqrt(pow($duzina, 2) + pow($sirina, 2));

echo '<div class="alert alert-warning mt-3" role="alert">';


echo "<strong>Rezultati:</strong><br>";
echo "Površina: $povrsina<br>";
echo "Obim: $obim<br>";
echo "Dijagonala: " . round($dijagonala, 2);
echo '</div>';
}
?>
</div>

<a href="index.php" class="btn btn-secondary mt-4">Vrati se na izbornik za


grupe</a>
<hr>
<small>&copy;<?php echo date('Y'); ?> <a href="http://bradhussey.ca/"><?php
echo $myName; ?></a></small>
</div>

</body>

</html>

You might also like