John Davidson

php - problem with loops while to calculate primary numbers who end with 9

0 comments
Message:


I would like to make a program which can calculate first 5000 primary numbers whos ends with 9 :


I tried this but it didn't work :


$div9 = [];
$x = 2;


while (count($div9) <= 5000) {
function findPrime($x)
{
for ($i = 2; $i < ($x / 2); $i++) {
$rest = $x % $i;
if ($rest == 0) {
break;
}
}
return $x;
}

$primeList[] = $x;

for ($j = 0; $j < count($primeList); $j++) {
$array = array_map('intval', str_split($primeList[$j]));
if (end($array[$j]) === 9) {
return $primeList[$j];
$div9[] = $primeList[$j];
}
}


$x++;
}

any hints please?



My Answer:

Rate this post

3 of 5 based on 5019 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us