#include <cstdlib>
#include <iostream>
using namespace std;
class hitung_Gcd {
public :
int gcd_iteratif(int c, int d);
int gcd(int c, int d);
private:
int bil1, bil2;
int hasil;
};
int hitung_Gcd::gcd_iteratif(int c, int d)
{ int r;
while (d > 0) {
r = c % d;
c = d;
d = r;
}
return (c);
}
int hitung_Gcd::gcd(int c, int d)
{
if (d==0) return(c);
if (c<d) return(gcd(d,c));
return(gcd(c-d, d));
}
int main(int argc, char *argv[])
{
hitung_Gcd X;
int a = 20, b = 10;
cout << "Gcd (iteratif) dari : " << X.gcd_iteratif(a,b) << endl;
cout << "Gcd (rekursi) dari : " << X.gcd(a,b) << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
0 Response for the "Greet Common Divisor C++"
Post a Comment