/*
*
* sum of odd natural number
* */
$x = 3;
$result = 0;
while($x){
$result =$result + (2 * $x--)-1;
}
echo $result;
/*
*
* sum of odd natural number in another way
* */
$n = 4;
$sum = 0;
$i = 1;
while($n--){
$sum += $i;
$i = $i + 2;
}
echo $sum;
*
* sum of odd natural number
* */
$x = 3;
$result = 0;
while($x){
$result =$result + (2 * $x--)-1;
}
echo $result;
/*
*
* sum of odd natural number in another way
* */
$n = 4;
$sum = 0;
$i = 1;
while($n--){
$sum += $i;
$i = $i + 2;
}
echo $sum;
No comments:
Post a Comment