(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

Using Euclid's algorithm write a program with a function that determines and returns the GCD of two integer arguments.

This is what i wrote, when i print the remainder is zero, How can i get the last remaninder before the zero value?

Thanks

2. Relevant equations

3. The attempt at a solution

[

#include <iostream>

using namespace std;

void remainder ( int, int); //Function Prototype

int main ()

{

int a, b;

cout << "This Program calculates the GCD of two integers \n"

<< "Please enter two integers" << endl;

cin >> a >> b;

remainder (a, b); //Calling the Function

return 0;

}

void remainder ( int a, int b) //Remainder function

{

int x, remainder;

remainder = 0;

int r;

if (a > b)

{r = b;

r %= b;

}

else

{r = a;

r %= b;

}

cout << r << endl;

}

]

1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Euclide's Algorithm to Calculate GCD

**Physics Forums | Science Articles, Homework Help, Discussion**