Pretty much exactly what the title says,
I tried using a for i=1 loop but didn’t go to plan
Thanks in advanced!
Pretty much exactly what the title says,
I tried using a for i=1 loop but didn’t go to plan
Thanks in advanced!
local number = 64 --Whatever number it is, you can change this whenever
local highestMultiple = 100
local matches = {}
for i = 1, highestMultiple, 1 do
if number % i == 0 then
table.insert(matches, i)
end
end
--then to display the results:
for i, v in ipairs(matches) do
print(number.." is in the time tables of "..v)
end
omg I completely misread the question
Use the modulo operator, for example:
local number = 1234 --whatever number you desire
count = 1
repeat
count += 1
until number % count == 0
print(string.format("The number %d belongs to the %d times table.", number, count))
This will catch the first times table the number is a member of (not all of its factors), 1 has been excluded for obvious reasons.
Same, I thought he meant how many times a number appears in a table
Well. It really depends on how many factors you want to find.
The most efficient way to do it is to loop all prime numbers up until the number / 2 as 2 is the smallest prime number.
If you want to find the biggest factor you just have too loop all the prime numbers until you find the smallest. Then if you found the prime number divide it with the number and you will get the largest factor