Sunday, 24 August 2014

Find GCD using Euclidean Algorithm

#include<iostream>
using namespace std;

void GcdFinder ( int a,int b )

{

    while ( a!=b )
  {
        if ( a>b ) {
            a=a-b;
        }
        else {
            b=b-a;
        }

    }
    cout<<"GCD Of two numbers is "<<a<<endl;
}
int main()
{
    int a,b;
    cout<<"Enter two numbers\n";
    cin>>a>>b;
    GcdFinder ( a,b );
    getchar();
    return 0;
}

No comments:

Post a Comment