The following table provides few examples of GCD of the given numbers.
15, 30 , 45
GCD of Two Numbers
In the following example, we will find the GCD of the given two numbers (45, 90).
#include<iostream>using namespace std;
int num1 =45;
int num2 =90;
int gcd =1;
for(i=2; i<=num1 && i <= num2; i++)
// Checks if i is factor of both integersif(num1 % i == 0 && num2 % i ==0)
gcd = i;
cout <<"GCD of "<< num1 <<" and "<< num2 <<": "<< gcd;