// Write a program to find the GCD and LCM of two numbers using functions
#include<iostream.h>
#include<conio.h>
int a,b;
int gcd(int a,int b)
{
int r;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
return(a);
}
void main()
{
int gcd(int x,int y);
int product,lcm,g;
clrscr();
cout<<"Enter two numbers: ";
cin>>a>>b;
product=a*b;
g=gcd(a,b);
lcm=product/g;
cout<<"GCD="<<g<<endl;
cout<<"LCM="<<lcm<<endl;
getch();
}

No comments: