please explain this c++ program?

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();
}
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?
I am not able to understand this program.
why we are returning only m why not n?
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.