/*
gcd.cpp
A program that implements the euclidean algorithm in order to find
the greatest common denominator
input instructions
integer1 integer2
Nikolai Banasihan, March 21, 2009, 9.17a
released under GNU General Public License version 2
Copyright (C) 2009 Nikolai Banasihan
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include
#include
using namespace std;
int main(int argc, char** argv)
{
// functions to be used
int gcd(int, int);
// main executable
if (argc < 3)
{
cout << "Lacking integer parameters." << endl;
}
else
{
// extract the arguments from argv
int x = atoi(argv[1]);
int y = atoi(argv[2]);
// output gcd value
cout << "GCD: " << gcd(x, y) << endl;
}
return 0;
}
int gcd(int x, int y)
{
int dummy;
while (x != 0)
{
if (y > x)
{
dummy = x; x = y; y = dummy;
}
x %= y;
}
return y;
}