In mathematics, the Greatest Common Divisor (GCD), also referred to as sometimes Greatest Common Factor (GCF), Highest Common Factor (HCF), Greatest Common Measure (GCM), Highest Common Divisor (HCD) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. This program will find Greatest Common Divisor (GCD) using C++. It will take two values from the user as input and and compute its GCD.

Following is the sequence of interaction with user when the program is run:
1. The User will be asked to “Enter the First Number: “.
2. The User will be asked to “Enter the Second Number: “.
3. Message will be Displayed “Computing GCD”.
4. Result will be displayed to the User “Greatest Common Divisor (GCD) is: “.

using namespace std;
int main() {

int first_num;
cout<<"Enter First Number: ";cin>>first_num;
int  second_num;
cout<<"Enter Second Number: ";cin>>second_num;
int  gcd;
cout<<"Computing GCD ... "<<endl;
for(int i=1; i<=first_num && i<=second_num; i++)
  if(first_num%i==0 && second_num%i == 0 ){

cout<<"Greatest Common Divison (GCD) is: "<<gcd<<endl;
return 0;
Tagged with: C/C++ languageSource Code

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.