LCM of Three Numbers C Program asked in Wipro NLTH

Ques: How to Find LCM of three numbers.

You will find code in these languages:-

  • C
  • C++
  • Java

If you can write a program to find LCM of two numbers. Then you can very easily write a program to find LCM of three numbers also , cause  lcm(a,b,c)=lcm(a,lcm(b,c))

“>

lcm(a,b,c)lcm(a,lcm(b,c))lcm(a,b,c)=lcm(a,lcm(b,c))

.

So here’s your c program to find LCM of three numbers.

Please write your version or code in other Languages below in comments.

Disclaimer-: The questions provided on this page are only model practice questions there is no surety that these questions have been previously asked in any company placement papers, these questions here only have the sole purpose to make you practice coding questions

5 comments on “LCM of Three Numbers C Program asked in Wipro NLTH”


  • bandaruyashwanth1

    #Program to print LCM of 3 numbers
    #Take 3 numbers as Input
    a=int(input())
    b=int(input())
    c=int(input())
    #Function to calculate LCM, function call will return LCM
    def LCM(a,b,c):
    product=a*b*c
    if a>b and a>c:
    m=a
    elif b>a and b>c:
    m=b
    else:
    m=c
    for i in range(m,product+1):
    count=0
    if i%a==0:
    count=count+1
    if i%b==0:
    count=count+1
    if i%c==0:
    count=count+1
    if count==3:
    break
    return i

    res=LCM(a,b,c)

    #Printing result
    print(res)


  • Aditi

    import java.util.Scanner;

    public class LCM{
    public static void main(String args[]){
    Scanner s= new Scanner(System.in);
    int a,b,c,g,p,i;
    System.out.println(“enter a,b,c values”);
    a=s.nextInt();
    b=s.nextInt();
    c=s.nextInt();
    p=a*b*c;
    g=a>b&&a>c?a: Math.max(b, c);
    for(i=g;i<=p;i=i+g){
    if(i%a==0 &&i%b==0 && i%c==0){
    break;
    }
    }
    System.out.println(i);
    s.close();

    }
    }


  • Aishwarya

    def lcm(num1, num2):
    temp=num2
    while True:
    if(temp % num2 == 0 and temp % num1 == 0):
    return temp
    temp+=1
    print(‘Enter three numbers: ‘)
    a = int(input())
    b = int(input())
    c = int(input())

    if(a<b):
    two = lcm(a,b)
    else:
    two = lcm(b,a)

    if(two<c):
    result=lcm(two,c)
    else:
    result=lcm(c,two)

    print('The LCM of three numbers is: ',result)


  • Varshitha

    #Python
    import math
    def lcm(x,y,z):
    lcm=x*y//math.gcd(x,y)
    lcm=lcm*z//math.gcd(lcm,z)
    return lcm
    x=int(input())
    y=int(input())
    z=int(input())
    print(lcm(x,y,z))


  • Rekha Reddy

    #in python
    def lcm(x,y):
    if x > y:
    grt=x
    else:
    grt=y
    while(True):
    if((grt%x==0) and(grt%y==0)):
    lcm=grt
    break
    grt+=1
    return lcm
    n= int(input())
    m=int(input())
    o=int(input())
    if n<m:
    l=lcm(n,m)
    else:
    l=lcm(m,n)
    if l<o:
    k=lcm(l,o)
    else:
    k=lcm(o,l)
    print(k)