aVenger
2007-04-10, 04:42:36
Es wird immer ausgegeben das es sich um KEINE Primzahl handelt. Kann mir einer sagen was da falsch ist?
<?php
//führt die Berechnung durch
function calc($wert)
{
if (isset($wert) && trim($wert)!='')
{
if ($wert < 2) {
return false;
}
else if ($wert == 2) {
return true;
}
else if ($wert%2 == 0) {
return false;
}
else {
for ($i=3; $i*$i<=$wert; $i+=2) {
if ($wert%$i==0) {
return false;
}
}
return true;
}
}
}
calc($_POST['wert']) ;
?>
<html>
<head>
<title>Primzahlenüberprüfung</title>
</head>
<body>
<h1>Primzahlenüberprüfung</h1>
<?php
if (calc($wert)==true ) echo "Primzahl";
if (calc($wert)==false) echo "KEINE Primzahl";
?>
<form action="index.php" method="post">
<table width="100px">
<tr>
<td><input type="text" size="40" name="wert"></td>
</tr>
<tr>
<td><input type="submit" value="überprüfen"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
//führt die Berechnung durch
function calc($wert)
{
if (isset($wert) && trim($wert)!='')
{
if ($wert < 2) {
return false;
}
else if ($wert == 2) {
return true;
}
else if ($wert%2 == 0) {
return false;
}
else {
for ($i=3; $i*$i<=$wert; $i+=2) {
if ($wert%$i==0) {
return false;
}
}
return true;
}
}
}
calc($_POST['wert']) ;
?>
<html>
<head>
<title>Primzahlenüberprüfung</title>
</head>
<body>
<h1>Primzahlenüberprüfung</h1>
<?php
if (calc($wert)==true ) echo "Primzahl";
if (calc($wert)==false) echo "KEINE Primzahl";
?>
<form action="index.php" method="post">
<table width="100px">
<tr>
<td><input type="text" size="40" name="wert"></td>
</tr>
<tr>
<td><input type="submit" value="überprüfen"></td>
</tr>
</table>
</form>
</body>
</html>