<?php
function isPrimeNumber($num) {
$isPrime = 1;
for ($i = 2; $i <= ($num/2); $i++) {
if ($num % $i == 0){
$isPrime = 0;
break;
}
}
return ($isPrime==1 || $num==2)? 1 : 0;
}
function generateRightTriangle( $rows ) {
define("START",2);
for ($i = 1, $count = START; $i <= $rows; $i++) {
for ($j = 1; $j <= $i; $j++) {
while( !isPrimeNumber($count) ){
$count++;
}
printf(" %-2d", $count);
$count++;
}
printf("\n");
}
return true;
}
if (!generateRightTriangle(5)) {
trigger_error("An error has occurred!");
}
- Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- 2
3 5
7 11 13
17 19 23 29
31 37 41 43 47
preferences:
180.83 ms | 403 KiB | 164 Q