+ 9
Challenge: negate number without using minus sign
hey, heres a little challenge: negate a integer but dont use the minus sign. eg: input: 123 //some code without "-" in it output: -123 Answer: https://code.sololearn.com/ctZF3srL79rG/?ref=app
14 odpowiedzi
+ 20
//For JavaScript
alert(~parseInt(prompt("Enter a no"))+1)
+ 13
is this accepted?
edit:
JS based on @Ace's solution
/////////
var neg = (num) => ~num + 1;
for(var i = 0; i < 20; i++){
var num = Math.floor(Math.random()*999999999);
console.log(`Original: ${num}\nNegative: ${neg(num)}\n`);
}
//////////
https://code.sololearn.com/c8J5t6j4PPcI/?ref=app
+ 13
https://code.sololearn.com/c9Q8ET5pEAhP/?ref=app
+ 7
No literal minus sign but...
https://code.sololearn.com/cgkhwg90141Q/?ref=app
It follows the rules but it’s more a joke than anything else 😁
+ 5
oops posted the wrong one, https://code.sololearn.com/WVzhIQ1ASV9h/?ref=app now it's okay I guess.
But my code is similar with @Burey's one, and I am not sure how to do it on the other way...
+ 5
i like all of your submissions so far, very creative :)
+ 1
https://code.sololearn.com/cEzLJeH1anud/?ref=app
+ 1
@Daniel you used the minus sign :p
+ 1
As I didnt see any Python Code, here is a similar one to your example Code but in Python =D
https://code.sololearn.com/cpn8JaGuvLZe/?ref=app