Write a PHP Script to sum of odd numbers from 1 to 10

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. $total = 0;
  2. $number = 0;
  3.  
  4. while ($number <= 10)
  5. {
  6. if ($number % 2 == 1)
  7. {
  8. $total = $total + $number;
  9. }
  10. $number++;
  11. }
  12.  
  13. echo $total;
  14.  
  15. ?>
  16.  

Result

python language techstudy.org

     





Related Topics




Popular Posts