Discuss Scratch

CrownIR1
Scratcher
100+ posts

Finding a multiple of a number?

I want to know how to find a multiple of a number.
I've already searched for answers and my brain is like "(╯°□°)╯︵ ┻━┻ HOW DO I IMPLEMENT THIS!!!"

Apparently, it has something to do with a mod operator. I have absolutely no idea how that works.
Calling back to
"(╯°□°)╯︵ ┻━┻ HOW DO I IMPLEMENT THIS!!!"
I think you can see my problem.


/(o_o)\
bcs320jn
Scratcher
100+ posts

Finding a multiple of a number?

There is a block for multiplication…
(() * (0))
And if you put that into an if statement, it goes like this:
set [Counter v] to [0]
delete all of [Multiples v]
repeat [Number of multiples you want to find]
change [Counter v] by (1)
add ([Whatever number you want to find multiples of] * (Counter)) to [Multiples v]
end
Scratch-Minion
Scratcher
1000+ posts

Finding a multiple of a number?

Multiples of 12 would be 12, 24, 36, 48 …

I suspect you might really want to find the Factors of 12 which are 1,2,3,4,6 and 12

delete (All v) of [Factors v]
set [n v] to [1]
repeat (Number)
if <((Number) mod (n)) = (0)> then
add (n) to [Factors v]
end
change [n v] by (1)
end

The “mod” operator gives the remainder after dividing the first number by the second number
eg. 12 mod 4 = 0 (remainder after dividing by 4)
12 mod 5 = 2 (remainder after dividing by 5)
12 mod 6 = 0 (remainder after dividing by 6)
12 mod 7 = 5 (remainder after dividing by 7)
so 4 and 6 would be two of the factors of 12 as there is no remainder after dividing 12 by 4 or 6.

Powered by DjangoBB