initial commit
This commit is contained in:
79
index.php
Normal file
79
index.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Primzahlen</title>
|
||||||
|
<style>
|
||||||
|
.wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 20px;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Primzahlenberechnung</h1>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div>
|
||||||
|
<form action="index.php" method="post">
|
||||||
|
<label>Input:
|
||||||
|
<input type="number" name="input">
|
||||||
|
</label>
|
||||||
|
<button type="submit">Berechnen</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if(isset($_POST['input'])) {
|
||||||
|
$primeNumbers = [];
|
||||||
|
$max = (int) $_POST['input'];
|
||||||
|
|
||||||
|
for($i = 0; $i <= $max; $i++) {
|
||||||
|
if(isPrime($i)) {
|
||||||
|
$primeNumbers[] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<h3>Primzahlen von " . htmlspecialchars($_POST["input"], ENT_QUOTES, 'UTF-8') . " sind:</h3>";
|
||||||
|
|
||||||
|
foreach($primeNumbers as $number) {
|
||||||
|
echo "<span>" . $number . "</span><br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPrime($i) {
|
||||||
|
if ($i <= 1) return false;
|
||||||
|
if ($i <= 3) return true;
|
||||||
|
if ($i % 2 == 0) return false;
|
||||||
|
|
||||||
|
for ($j = 3; $j * $j <= $i; $j += 2) {
|
||||||
|
if ($i % $j == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h3>Logarithmische Funktion (n = 1..100)</h3>
|
||||||
|
<div class="mono">
|
||||||
|
<?php
|
||||||
|
for ($n = 1; $n <= 100; $n++) {
|
||||||
|
$ln = log($n);
|
||||||
|
$lnFormatted = number_format($ln, 4, '.', '');
|
||||||
|
|
||||||
|
$starsCount = (int) floor($ln);
|
||||||
|
$stars = $starsCount > 0 ? str_repeat('*', $starsCount) : '-';
|
||||||
|
|
||||||
|
echo sprintf("%3d: ln=%6s %s<br>", $n, $lnFormatted, $stars);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user