Write a program in PHP to find the sum of first 20 even number


<?php
#Write a program in PHP to find the sum of first 20 even number
$sum=0;
for($i=1;$i<=40;$i++)
{
 if($i%2==0)
 {
  $sum=$sum+$i;
 }
 
}
echo "Sum of first 20 even number is ",$sum,"<br>";
?>
Output:
Sum of first 20 even number is 420

Comments