trying to write a fuction to work out the GCD of two numbers
seems to run ok but the return is incorrect
any help much appreciated
#include <iostream>
#include <cmath>
using namespace std;
int g_c_d(int a,int b);
int main()
{
cout<<g_c_d(2871,4060);/*test example*/
cout<<endl;
system("pause");/*been advised not to use this but at my level well hey!*/
return 0;
}
int g_c_d(int a,int b)
{
int c;
c=abs(b-a);
cout<<a<<" "<<b<<" "<<c<<endl;/*put this in to check it was going ok*/
if(c==0){return a;}
if(b>a){b=a;}
a=c;
g_c_d(a,b);
}
returns 4249024 instead of 29
sorry this may be double post just new to this
didnt know wether it should be code snippet or discussion thread