0

I'm new at programming, I was asked to create a program to find the GCD (Greatest common divisor) of two numbers my friend helped me create this program.

All i am asking is how does it function?, I know how the whole program works (If... If else, While, Looping, Modulo etc.) and how to find the GCD.

But i dont know how my program does it.

```
#include <iostream.h>
#include <conio.h>
int gcd(int a, int b);
int a, b;
int main()
{
clrscr();
cout<<"Enter the A Integer: ";
cin>>a;
cout<<"Enter the B Integer: ";
cin>>b;
gcd(a, b);
getch();
return 0;
}
int gcd(int a, int b)
{
int r;
if (a>b)
{
while (b!=0)
{
r=a%b;
a=b;
b=r;
}
cout<<"Greatest Common Divisor is: "<<a;
}
else if (b>a)
{
while (a!=0)
{
r=b%a;
b=a;
a=r;
}
cout<<"Greatest Common Divisor is: "<<b;
}
else
{
clrscr();
cout<<"Error!";
}
getch();
return 0;
}
```