Question 1

LCM – Least Common Multiple of both the numbers

Rules:

  • Have any common multiple except 1
  • Always greater than or equal to the maximum number

Algorithm:

#1.Find the maximum and minimum number

#2.Loop from 1 till the minimum number

#3.Find the multiple of the maximum number

#4.Check the multiple of maximum number is also a multiple of minimum number

#5.If the multiple is exactly divisible, then it is the LCM and return from the loop

#6.If the multiple is not exactly divisible, then continue with the loop

Explanation:

Ex: LCM(5,7)

7=1*7(7),2*7(14),3*7(21),4*7(28),5*7(35)

5=1*5(5),2*5(10),3*5(15),4*5(20),5*5(25),6*5(30),7*5(35)

LCM(5,7)=35

max=7, min=5

for(int i=1;i<min;i++) multiple=i*max If(multiple%min==0) lcm=multiple
1;1<=5;1++ 1*7=7 7%5=2==0(false)
2;2<=5;2++ 2*7=14 14%5=4==0(false)
3;3<=5;3++ 3*7=21 21%5=1==0(false)
4;4<=5;4++ 4*7=28 28%5=3==0(false)
5;5<=5;5++ 5*7=35 35%5=0==0(true) lcm=35

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s