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

20th Mar 2019, 10:08 PM
yadira Castellanos
yadira Castellanos - avatar
7 Respostas
+ 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 😊
21st Mar 2019, 12:15 AM
LynTon
LynTon - avatar
+ 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).
21st Mar 2019, 1:33 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Paulo Victor Lund de Sá Villela Ah ok I've never actually used the PHP CLI, thanks for the note 👍
21st Mar 2019, 12:45 AM
LynTon
LynTon - avatar
+ 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
20th Mar 2019, 11:02 PM
Paulo Victor Lund de Sá Villela
Paulo Victor Lund de Sá Villela - avatar
+ 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)
21st Mar 2019, 12:35 AM
Paulo Victor Lund de Sá Villela
Paulo Victor Lund de Sá Villela - avatar
+ 1
Muchas gracias!
21st Mar 2019, 12:50 AM
yadira Castellanos
yadira Castellanos - avatar
0
Bro...
23rd Mar 2019, 7:01 PM
Pavel Hasan
Pavel Hasan - avatar