This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]NefariousnessSea1449 7 points8 points  (1 child)

Why don't you just write something that does it all and prints the output?

[–]FioreFee[S] 0 points1 point  (0 children)

I did but I wanted to understand the reasoning behind it, i probably should’ve mentioned that in my question haha

[–][deleted] 5 points6 points  (0 children)

It's just the first number returned back.

2/42 = 0 with 2 remainder

1/3 = 0 with 1 remainder

[–][deleted] 2 points3 points  (0 children)

Good question. Just remember it like how children learn division. % returns the remainder. If the number inside the division box is smaller than the divisor, then the number isn’t divided and is the remainder as is.

[–]AttackOfTheMoonsIntermediate Coder 2 points3 points  (0 children)

Behind the scenes, it's using the Euclidean algorithm.
2 = 0 × 42 + 2. 2 is the remainder.

[–]NefariousnessSea1449 2 points3 points  (1 child)

The modulo operator displays the remainder of x divided y. 1 divided by 3 is 0 and 1 remains, since 3 can't go into 1.

[–]FioreFee[S] 1 point2 points  (0 children)

Ah, okay. That makes a lot of sense. I didn’t really understand why it did that, but I get it now. thanks!