سؤال

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