- <?php
- //FrequenTech program in PHP to find the sum of first 20 even numbers
//Declaration of class
- class AddEvenNumber
- {
//Declaring three required private INT variables
private $i = 0;
private $j = 0;
private $addVar = 0;
//public function to perform operation
public function evenNum(){
while ($this->j<20){
if($this->i%2 == 0){
$this->addVar+= $this->i;
$this->j++;
}
$this->i++;
}
return $this->addVar;
}
}
- $addResult = new AddEvenNumber();
- $result = $addResult->evenNum();
- echo "Addition of first 20 Even Number is: ".$result;
- OUTPUT:
- Addition of first 20 Even Number is: 380
Generally I do not learn post on blogs, but I would like to say that this write-up very forced me to take a look at and do it! Your writing style has been amazed me. Thanks, quite great post. Dorothee Mano Maxy