C++ Programme to find the LCM and GCD of two numbers.

programme to find a LCM  and GCD of two numbers.


#include<iostream.h>
#include<conio.h>
void main()
{
                clrscr();

                int x,y,gcd=1;

                cout<<    "ENTER 1st NO  : ";
                cin>>x;

                cout<<"\n\nEnter 2nd NO. :";
                cin>>y;

                for(int i=1;i<1000;++i)
                {
                                if((x%i==0)&&(y%i==0))
                                gcd=i;
                }

                cout<<"\n\n\nGCD :"<<gcd;
                cout<<"\n\n\nLCM :"<<(x*y)/gcd;

                getch();
}






OUTPUT:

ENTER 1st NO  : 12

ENTER 2nd NO. :13

GCD :1

LCM :156

No comments:

Post a Comment