문제

So i have this number 1234567890 declared as this.

local num = 1234567890; 

and now i what to add those numbers together 2+4+6+8+0 so would i go about this?

도움이 되었습니까?

해결책

Try this:

local num = 1234567890
local sum = 0
for a,b in tostring(num):gmatch("(.)(.)") do
    sum=sum+tonumber(b)
end
print(sum)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top