Prime Number In PHP
//Prime Number: 5 to 250 task...
$prime = 250;
echo "<h1 style=color:red;text-align:center;background-color:black;font-size:50px;>Prime Number: 5 to 250...</h1>";
//ye loop 5 se lekar 250 tak chalayega.
for ($i=5; $i <= $prime; $i++) {
$isprime = true;
//ye loop i divided by 2 aur if statement reminder nikalega 0 hua to false aur 1 hua to true.
for ($j=2; $j <= ($i/2); $j++) {
if ($i % $j == 0) { //aur if statement reminder nikalega 0 hua to false aur 1 hua to true.
$isprime = false;
}
}
if ($isprime == true) {
echo "This is Prime Number: ".$i.'<br>';
}
}
-----------------------------------------------------------------------------------------------------------------------------
Task
while loop 5 to 250.
$a = 5;
while ($a <= 250)
{
$c = $a-1;
$d = $a+1;
echo $c.", ".$a.", ".$d.'<br>';
$a++;
}
-----------------------------------------------------------------------------------------------------------------------------
Task
for loop 5 to 250
$x = 5;
for ($i=$x; $i <= 250 ; $i++) {
$num = 0;
for ($j=1; $j < $x ; $j++) {
if ($x % $j==0) {
$num++;
}
}
if ($num <= 2) {
echo $x."<br>";
}
$x++;
}
-----------------------------------------------------------------------------------------------------------------------------
STAR PATTEN Using For Loop
for ($i=1; $i <= 10; $i++) {
for ($j=1; $j <= $i; $j++) {
echo "*";
}
echo "<br>";
}
Comments
Post a Comment