“GCD in CPP” Code-Antworten

GCD -Funktion c

ll gcd(ll a, ll b)
{
    if (b==0)return a;
    return gcd(b, a % b);   
}
Ugliest Unicorn

C Finden von GCD

// CPP program to illustrate
// undefined behavior of
// gcd function of C++ STL
#include <iostream>
#include <algorithm>
// #include<numeric> for C++17
 
using namespace std;
 
int main()
{
    cout << "gcd(6, 20) = " << __gcd(2.0, 8) << endl; // gcd(2.0,8) for C++17
}
TheBeautiful World

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;
}
Lucky Lemur

Ähnliche Antworten wie “GCD in CPP”

Fragen ähnlich wie “GCD in CPP”

Weitere verwandte Antworten zu “GCD in CPP” auf C++

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen