Пример #1
0
function SimpleAdding($num)
{
    //if number is greater than 1
    if ($num > 1) {
        $total = $num + SimpleAdding($num - 1);
    } else {
        $total = $total + 1;
    }
    return $total;
}
Пример #2
0
<?php

/*
	Using PHP, have the function SimpleAdding(num) add up all the numbers from 1 to num. 
	For the test cases, the parameter num will be any number from 1 to 1000. 
*/
function SimpleAdding($num)
{
    $sum = 0;
    for ($i = 1; $i <= $num; $i++) {
        $sum = $sum + $i;
    }
    return $sum;
}
//Test
echo SimpleAdding(140);