A triangular number is the sum of the n natural numbers from 1 to n.
ASP
function triangularNumber(someNumber)
dim i
dim result
result = 0
for i = 1 to someNumber
result = result + i
next
triangularNumber = result
end function
PHP
function triangularNumber($number)
{
for($i = 1; $i <= $number; $i++)
{
$result += $i;
}
return $result;
}
No comments:
Post a Comment