Pages

Write a program to find GCD and LCM in C++ language

Friday, 21 February 2014

#include <iostream>
using namespace std;

int main()
{
    int a, b, temp, gcd, lcm, x, y;
    cout << "Enter two number: ";
    cin >> x>>y;
   
    a = x;
    b = y;
   
    while(b!= 0)
    {
           temp = b;
           b = a%b;
           a = temp;
    }
   
    gcd = a;
    lcm = x*y/gcd;
   
    cout << "GCD is: "<<gcd<<"\nLCM is: "<<lcm<<endl;
    system("pause");
}

 

Search Box

Most Reading

Contact Form

Name

Email *

Message *