/* example of a program with no explicit loops * input is two integers, output is greatest common divisor */ #include #include #include using namespace std; int x, y; // global :( !! class FO { public: bool operator() (int arg){ if (x > y) x-=y; else if ( y > x ) y -= x; return x == y; } }; int main() { cin >> x >> y; FO euclid; int m = max(x, y), arr[m]; int ntimes = find_if(arr, arr+m, euclid) - arr + 1; cout << "gcd = " << x << " numIter " << ntimes << endl; return 0; }