+ 19

[CHALLENGE] negative numbers

Another simple challenge. Make all numbers negative except 0. You have integers: 42, -9, 29, -32, 19, 0 . Final data: -42, -9, -29, -32, -19, 0.

15th Feb 2018, 1:36 PM
r8w9
r8w9 - avatar
25 Answers
15th Feb 2018, 1:57 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 17
https://code.sololearn.com/crtA722OkyyF/?ref=app
15th Feb 2018, 5:07 PM
Daljeet Singh
Daljeet Singh - avatar
+ 13
I took a break from my favourite​ C++ and wrote in Ruby: https://code.sololearn.com/c6Ly5ZQt79IT/?ref=app
16th Feb 2018, 2:03 AM
Eric Zatarack
Eric Zatarack - avatar
+ 10
https://code.sololearn.com/cL0Q7ZpO9wZX/?ref=app https://code.sololearn.com/ce1oQDP13CsV/?ref=app
9th May 2018, 3:10 PM
Uni
Uni - avatar
+ 8
Hiya! Did you submit this as an assignment via lesson factory? It would be great if you could!
15th Feb 2018, 3:04 PM
jay
jay - avatar
+ 8
Here's another approach in C++, nice challenge. Thanks : ) https://code.sololearn.com/cGOUcDx3JJ0I/?ref=app
16th Feb 2018, 6:55 AM
Ipang
15th Feb 2018, 1:45 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
15th Feb 2018, 5:53 PM
🐙evil octopus
🐙evil octopus - avatar
15th Feb 2018, 6:14 PM
Med Arezki
Med Arezki - avatar
15th Feb 2018, 2:49 PM
‎ ‏‏‎Anonymous Guy
+ 5
Your solution is not perfectly correct :) ALL numbers must be negative. Your last negative number in list becomes positive. Try to fix it.
15th Feb 2018, 1:49 PM
r8w9
r8w9 - avatar
+ 5
return (nbr==0)?0:Math.abs(nbr)*-1
15th Feb 2018, 3:41 PM
Αητοιπe
Αητοιπe - avatar
+ 4
@A Z M Mushfiqur Rahman It is also not correct. You just rewrote it manually :) that's not good because when you add more numbers the code won't work.
15th Feb 2018, 4:28 PM
r8w9
r8w9 - avatar
+ 4
Here is my code in a more mathematical approach. Good challenge for learners! https://code.sololearn.com/coUQH44O5hZJ/?ref=app
15th Feb 2018, 10:40 PM
Andres Ballester
Andres Ballester - avatar
16th Feb 2018, 4:00 AM
Half Byte
Half Byte - avatar
+ 3
@jay I'll do it few minutes later :)
15th Feb 2018, 3:11 PM
r8w9
r8w9 - avatar
+ 3
@r8w9, correction is made in my code, please check now.
15th Feb 2018, 3:33 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
15th Feb 2018, 3:34 PM
Nitzan
Nitzan - avatar
+ 3
@r8w9, thanks,I'm working on it.
15th Feb 2018, 4:39 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
15th Feb 2018, 6:24 PM
Jozef