Or in Javascript... :P
function sumDigits(val) {
if (!isNaN(val)) {
val = parseInt(val, 10) // ensure integer
if (val>9) {
var sum = val%10 // last digit number
while (val>10) { // searching for the first number
val = parseInt(val/10, 10)
}
alert(sum+val) // now what left is the last + first digit
}
else { alert(val) }
}
else { alert(val+" is not a number") }
}
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239