#include <iostream>
using namespace std;

int main() {
    int num1, num2, smaller_num=0, hcf=1;
	cin>>num1>>num2;
    
	if(num1<num2)
	{
		smaller_num = num1;
	}
	else
	{
		smaller_num = num2;
	}

/*
	for(int i=1; i<=smaller_num;i++)
	{
		if((num1%i==0) && (num2%i==0))
		{
			hcf=i;
		}
	}
*/

    //This is more quicker approach
    for(int i=smaller_num; i>=1;i++)
	{
		if((num1%i==0) && (num2%i==0))
		{
			hcf=i;
            break;
		}
	}

   cout<<hcf;
   return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: