+ 10
Challenge - How to find the sum of even digits and odd digits of a given number...?
Example: number = 123 even digit sum = 4{1+3} odd digit sum = 2 Try to find optimal solution..
16 Respostas
+ 13
https://code.sololearn.com/ce2T5a3RVu44/?ref=app
+ 12
Here you go, as you asked :
https://code.sololearn.com/c6PjKAJIToE3/?ref=app
+ 11
what i do
take a num n
get the first digit (using n%10)
check if even then
add its value to even number
else it is odd
add its value to odd number
divide n by 10(to get the next digit)
repeat using for() until n become 0( no digit to add)
+ 9
https://code.sololearn.com/cGYq3dOkjCkN/?ref=app
+ 8
Number.prototype.sum = function(chk) {
return this.toString().split("").filter((n)=>n%2==chk).reduce((s,n)=>s += +n,0);
}
https://code.sololearn.com/Wc8sEf86tc7B/?ref=app
+ 8
Java, using String to int conversion:
https://code.sololearn.com/cdtd2WH451wd/?ref=app
Java, using bitwise operation:
https://code.sololearn.com/cDRQkynQ1b1K/?ref=app
+ 7
nice..... is there any optimal logic for this?
+ 5
@Natanaelk This is spam please delete it !!!