Help me understand this c++ 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
use code tags! this is not readable

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
29
30
31
32
33
34
35
36
/*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();
}
Topic archived. No new replies allowed.