Search
 
SCRIPT & CODE EXAMPLE
 

CPP

gcd function c++

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

c++ finding 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
}
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp detect os 
Cpp :: c++ #include 
Cpp :: how to generate number in c++ 
Cpp :: c++ for loop multiple variables 
Cpp :: attention nlp 
Cpp :: array of Methods c++ 
Cpp :: getline() 
Cpp :: vectors c++ 
Cpp :: log base 2 in c++ 
Cpp :: how to make a square root function in c++ without stl 
Cpp :: how to find even and odd numbers in c++ 
Cpp :: how to make a function in c++ 
Cpp :: iostream c++ 
Cpp :: looping in map c++ 
Cpp :: linux c++ sigint handler 
Cpp :: trie code cpp 
Cpp :: prevent copy c++ 
Cpp :: resharper fold statement 
Cpp :: how to reset linerenderer unity 
Cpp :: converting char to integer c++ 
Cpp :: google test assert throw 
Cpp :: how to create an integer in c++ 
Cpp :: find an element in vector of pair c++ 
Cpp :: how to find factorial of number in c++ 
Cpp :: web dev c++ 
Cpp :: operator overloading in c++ 
Cpp :: 1. Two Sum 
Cpp :: memset c++ 
Cpp :: c++ string example 
Cpp :: summation of numbers using function 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =