- #1

lcam2

- 28

- 0

## Homework Statement

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

## Homework Equations

## 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;

}

]