C++ Programming Code Examples C++ > Mathematics Code Examples C++ Program to Find GCD C++ Program to Find GCD Examples on different ways to calculate GCD of two integers (for both positive and negative integers) using loops and decision making statements. The largest integer which can perfectly divide two integers is known as GCD or HCF of those two numbers. In above program, smaller number is subtracted from larger number and that number is stored in place of larger number. This process is continued until, two numbers become equal which will be HCF. #include <iostream> using namespace std; int main() { int number1, number2; cout << "Enter two numbers: "; cin >> number1 >> number2; while(number1 != number2) { if(number1 > number2) number1 -= number2; else number2 -= number1; } cout << "HCF = " << number1; return 0; }