Show sourcecode
The following files exists in this folder. Click to view.
comments.php
exercises/
exercises.php
funktioner/
grunder/
img/
incl/
index-no-include.php
index.php
source.php
style/
txt_filer/
viewsource.php
övning1.php
övning2.php
övning3.php
övning4.php
övning5.php
övning6.php
övning7.php
övning6.php
31 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Primtal</title>
</head>
<body>
<?php
$primtal = [];
for ($tal = 2; $tal <= 100; $tal++) {
$arPrimtal = true;
for ($delare = 2; $delare < $tal; $delare++) {
if ($tal % $delare == 0) {
$arPrimtal = false;
break;
}
}
if ($arPrimtal) {
$primtal[] = $tal;
}
}
echo "Primtalen är: " . implode(", ", $primtal) . "<br>";
echo "Antal primtal: " . count($primtal);
?>
</body>
</html>