Write a PHP program to calculate the sum of even numbers up to 100?

Flowchart For Program: 

flowchart






Program:
<?php

$sum=0;
for($i =1; $i <= 100; $i++)
{
     if($i % 2 == 0)
     {
         $sum += $i;
      }
}
 echo "The Sum of  even number upto  ".$i." is: ".$sum;

?>

Explanation: In this program, we add even numbers up to 100. We simply use for loop that starts from 1 and ends on 100 you can change this value according to your requirement if for loop has true condition then we check that number is even or odd if the number is even then we add that number into sum whenever condition did not get false.

if you not understand the program or got any type of errror or problem then you can describe in comment section.

Post a Comment

أحدث أقدم