Friday, 10 October 2014

Write a c++ code to find Greatest Common Division (GCD)? (GCD:- It means the greatest number which divides the Both numbers)

Leave a Comment
#include"iostream"
#include"iomanip"
using namespace std;
int main()
{
int first_number,second_number,gcd;

cout<<"Enter First Number : ";
cin>>first_number;
cout<<"Enter Second Number: ";
cin>>second_number;
for(int i=1;i<=first_number&&i<=second_number;i++)

{
if(first_number%i==0 && second_number%i == 0 )


{

gcd=i;

}

}
cout<<endl<<setw(40)<<"Greatest Common Divison is: "<<gcd<<endl;

system("pause");

}

OUTPUT

If You Enjoyed This, Take 5 Seconds To Share It