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 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
int gcd(int, int);
int extended_gcd(int a, int b, int x);
int main()
{
int num1,num2,x,y;
int *ret = new int[3];
cout << "enter two integers:";
cin >> num1 >> num2;
cout << "gcd is " << endl;
ret = extended_gcd(num1, num2,x);// << endl;
cout << ret[0] << endl << ret[1] << endl << ret[2];
system("pause");
return 0;
}
/*/int gcd(int x, int y)
{
if (x % y == 0)
return y;
else
return gcd(y, x%y);
}
/*/
int extended_gcd(int a, int b, int x,int y)
{
int q, r;
double s, t;
int n;
if (b == 0)
// return (1,0);
cout << "x = 1" << endl << "y = 0";
else
{
q = a/b;
r = a%b;
extended_gcd(a, b, b,r);
extended_gcd(a,b,r, b);
cout << "x = " << t << endl;
cout << "y = " << (s-q*t) << endl;
}
return (t, (s-q*t), n);
|