Revise the program so that it prints out all the steps involved in the
algorithm. Here is a sample output:
GCF (500, 300) =>
GCF (300, 200) =>
GCF (200, 100) =>
GCF (100, 0) => //this line is not printing out.
100
the problem is that the last line is not printing out I mean the (100, 0) and I don't know why, please help me I don't know what I am doing wrong.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int Gcf(int a, int b);
void Print_gcf(int a, int b);
int main ()
{
int a = 0, b = 0;
cout << "Enter a: ";
cin >> a;
cout << "Enter b: ";
cin >> b;
cout << Gcf(a, b) << endl;
return 0;
}
int Gcf(int a, int b)
{
if (b == 0){
return a;
}
else{
Print_gcf(a,b);
return Gcf(b, a%b);
}
}
void Print_gcf(int a, int b)
{
cout << "GCF (" << a << ") " << "(" << b << ") => " << a%b <<endl;
}