“GCD di CPP” Kode Jawaban

Fungsi GCD c

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

C Menemukan 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 di 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

Jawaban yang mirip dengan “GCD di CPP”

Pertanyaan yang mirip dengan “GCD di CPP”

Lebih banyak jawaban terkait untuk “GCD di CPP” di C++

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya