Euclids Algorithm

#include "stdafx.h"
#include "iostream"
using namespace std;

 int gcd (int a, int b)
   {
     int temp;
     while (b != 0)
     {
       temp = a % b;
       a = b;
       b = temp;
     }
     return(a);
   }

int _tmain(int argc, _TCHAR* argv[])
{
       int x, y;
     cout << "Enter two natural numbers: ";
     cin >> x >> y;
     cout << "gcd(" << x << ", " << y << ") = " << gcd(x,y) << endl;
        system("pause");
       return 0;
}



Share on Google Plus