0
Alguien me podría ayudar con este ejercicio hacer un algoritmo que imprima la serie 2 5 7 10 12 15 17 19...1800 por favor
7 Réponses
+ 7
Here is a solution (explanation in code):
https://code.sololearn.com/cyn5ZrhXn64A/?ref=app
EDIT:
Paulo Victor Lund de Sá Villela Wait, actually your solution does work (although you might get a "time limit exceeded" message before your code can end), maybe you should make the numbers display on different lines to see it more clearly?
Try changing the line with this:
echo $num;
To this:
echo $num."<br />";
EDIT:
No Problem 😊
+ 29
● we can take general term as (5n/2) in Java.
● After that if we want last term to be K (1800 in this case), then solve 5n/2=k [n=1800*2/5=720 here for k=1800]
● so run the loop from n=1 to n=(2*k/5) & in each iteration print (5*n/2).
+ 4
Paulo Victor Lund de Sá Villela
Ah ok I've never actually used the PHP CLI, thanks for the note 👍
+ 3
I've tryied but i cant. I did this in php
<?php
$last_sum = 2;
$num = 2;
while ($num != 1800) {
echo $num;
if ($last_sum == 2) {
$num += 3;
$last_sum = 3;
} else {
$num += 2;
$last_sum = 2;
}
}
But when i reach 17, it add 20, cos doesn't have a sequence in your question
+ 2
LynTon I use php cli, and to avoid timeout, just set the time limit to -1.
Also, in cli you need to use \n or \r, not html x)
+ 1
Muchas gracias!
0
Bro...