Hi ladies and gents,
I made this exercise in wich recursion has to be used and it worked as it should:
void ggd(short x, short y)
{
short a = 0;
if (y == 0)
{
cout<<"The largest common divider is: "<< x <<endl;
}
else
{
a = (x% y);
x = y;
y = a;
x% a != 0 ? ggd(x, y) :cout<<"The largest common divider is: "<< a <<endl;
}
}
int main()
{
ggd(1147, 851);
cin.get();
return 0;
}
Now, I read the tutorial Dany made about this and she mentions:
Although recursion should generally be avoided, there are still algorithms which can only be solved with its use.
Wich algorithms are they, can someone give me some examples :?:
I mean, when do you really know you HAVE TO USE recursion :?: