Code that finds all the common multiples of two given numbers. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code that finds all the common multiples of two given numbers.

How would I create a code that finds all the common multiples of two given numbers? I’m not good at math and I’m lost lol. Any help is appreciated, thank you!

6th Feb 2018, 7:08 AM
KBEAST
2 Answers
+ 12
run a loop from 1 to smaller no if a%i==0&&b%i==0 , then i will be the common factor amongst them //print i everytime if above statement comes true
6th Feb 2018, 9:09 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
on sololearn code section are a lot of materials that you can use to wrote code you need. basically you should create a loop from 2 to smaller number and check which of these numbers divide both given numbers using % operander, you can just print result or save it in some array. i hope that i helped you, if you have more questions about this do not hesitate to ask.
6th Feb 2018, 7:40 AM
wolfsan
wolfsan - avatar