How can I create an application that will display perfect numbers from 1-100? The output should be 1 3 6 10 15 21 28.... Notice that the difference between the numbers are 2 3 4 5 6 7....
<?php
$one=0;
$two=1;
for ($x=0;$x<=45;$x++){
echo $nxt." ";
$cur=$one;
$nxt=$two;
$sum=$cur+$nxt;
$two=$sum;
}
?>
incrementing in php
Moderator: General Moderators
Re: incrementing in php
Sounds like a school programming problem 
One way is to use recursion and another way - to do it iteratively ...
You have:
x(0) = 0
x(n) = x(n-1) + n
So, implement it in a function
One way is to use recursion and another way - to do it iteratively ...
You have:
x(0) = 0
x(n) = x(n-1) + n
So, implement it in a function
There are 10 types of people in this world, those who understand binary and those who don't
Re: incrementing in php
Code: Select all
<?php
while ($x<100) { echo $x = $x + ++$y; }
Re: incrementing in php
i got it! thanx!