gcd and Lcm of 2 given no

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*please explain this program*/
/*Program to find GCD and LCM of given two numbers*/
#include<iostream.h>
#include<conio.h>
int gcd(int m,int n)
{while(m!=n)
{if(m>n)
m=m-n;
else
n=n-m;
}
return m;
}
int lcm(int m,int n)
{
return m*n/gcd(m,n);
}
void main()
{ int gcd(int,int);
int lcm(int,int);
int x,y;
clrscr();
cout<<"enter two numbers";
cin>>x>>y;
cout<<"GCD:"<<gcd(x,y);
cout<<endl<<"LCM:"<<lcm(x,y);
getch();
}
Last edited on
Stop reposting. We've answered your questions already.
Topic archived. No new replies allowed.