please explain this c++ program?

Feb 21, 2012 at 3:39pm
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
/*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();
}
Feb 21, 2012 at 3:43pm
yes this helps... but it could be better...;) And you could just have edited your previous post.

And to answer your question, the first line of your code gives you an answer.
What do you want to know exactly?
Feb 21, 2012 at 4:32pm
I am not able to understand this program.
Feb 21, 2012 at 4:33pm
why we are returning only m why not n?
Feb 22, 2012 at 7:39am
because of this:"

1
2
3
4
5
6
7
while(m!=n)
{
  if(m>n)
    m=m-n;
  else
    n=n-m;
}


m and n are the same when the loop ends.
Topic archived. No new replies allowed.