Horje
GCD in cpp Code Example
gcd function c++
ll gcd(ll a, ll b)
{
    if (b==0)return a;
    return gcd(b, a % b);   
}
GCD in cpp
#include <iostream>
using namespace std;

int main() {
  int n1, n2, hcf;
  cout << "Enter two numbers: ";
  cin >> n1 >> n2;

  // swapping variables n1 and n2 if n2 is greater than n1.
  if ( n2 > n1) {   
    int temp = n2;
    n2 = n1;
    n1 = temp;
  }
    
  for (int i = 1; i <=  n2; ++i) {
    if (n1 % i == 0 && n2 % i ==0) {
      hcf = i;
    }
  }

  cout << "HCF = " << hcf;

  return 0;
}




Cpp

Related
bit++ codeforces in c++ Code Example bit++ codeforces in c++ Code Example
what is meant by pragma once in c++ Code Example what is meant by pragma once in c++ Code Example
Round 1 Confusion codechef solution in c++ Code Example Round 1 Confusion codechef solution in c++ Code Example
notepad++ Code Example notepad++ Code Example
integer max value c++ Code Example integer max value c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9