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


Introduction

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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1.  
  2. <?php
  3. $primes = array();
  4. $is_prime_no = false;
  5. for ($i = 2; $i<200; $i++) {
  6. $is_prime_no = true;
  7. for ($j = 2; $j<=($i/2); $j++) {
  8. if ($i%$j==0) {
  9. $is_prime_no = false;
  10. break;
  11. }
  12. }
  13. if ($is_prime_no) {
  14. array_push($primes,$i);
  15. }
  16. if (count($primes)==200) {
  17. break;
  18. }
  19. }
  20. echo array_sum($primes)."\n";
  21. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts