/*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 (100, 0) =>
100*/
#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;
system ("PAUSE");
return 0;
}
int Gcf(int a, int b)
{
if (b == 0)
return a;
else
{
Print_gcf(a,b);
Gcf(b, a%b);
}
}
void Print_gcf(int a, int b)
{
cout << "GCF (" << a << ") " << "(" << b << ") => " << a%b <<endl;
}
everything runs fine except i always get 0 as the final answer. ive been stuck on this since 12pm last night and i cant figure it out. i key in 300 for a and 500 for b.
this is how i think its suppose to work:
a = 500
b = 300