Write a PHP script using a for loop to add all the integers between 0 and 20 and display the sum

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


techstudy.org

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

  1. <?php
  2. $sum = 0;
  3. for($x=1; $x<=20; $x++)
  4. {
  5. $sum +=$x;
  6. }
  7. echo "The sum of the numbers 0 to 20 is $sum"."\n";
  8. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts