Q:

Write a PHP program to compute the sum of the prime numbers less than 200

belongs to collection: PHP basic programs with examples

0

Write a PHP program to compute the sum of the prime numbers less than 200

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?php
$primes = array();
$is_prime_no = false;
for ($i = 2; $i<200; $i++) {
     $is_prime_no = true; 
        for ($j = 2; $j<=($i/2); $j++) {
                if ($i%$j==0) {
                          $is_prime_no = false;
                                  break;
                                }
                   }
        if ($is_prime_no) {
               array_push($primes,$i);
                  }
        if (count($primes)==200) {
               break;
                  }
}
echo array_sum($primes)."\n";
?>

Result:

4227

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP program to print out the multiplicatio... >>
<< Write a PHP program to remove duplicates from a so...