gcd in c++
C++
// CPP program to illustrate
// gcd function of C++ STL
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
cout << "gcd(6, 20) = " << __gcd(6, 20) << endl;
}
int gcd(int a, int b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
Also in C++:
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- inheritance protected in c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- factorion
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- c++ reset stream
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- deque c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- array search c++
- Category
- C++
- Title
- arduino delay millis
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++
- Title
- tree traversal c++ in order
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- COnvert string to char * C++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- c++ yes no question
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- c++ variable argument
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- vector initialization c++
- Category
- C++
- Title
- c++ compare char array
- Category
- C++
- Title
- how to compile opencv c++ in ubuntu
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- how to get the prime number in c++ where time complexity is 0(log n)
- Category
- C++
- Title
- initialize vector of pointers c++
- Category
- C++
- Title
- how to concatinate two strings in c++
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- c++ push multiple elements to vector
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- how to convert n space separated integers in c++
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- how to sort vector in c++
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- max element in array c++ stl
- Category
- C++
- Title
- how to input multiple lines of a file in c++
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorFloating-point exception (SIGFPE
- Category
- C++
- Title
- calculate sum in c++
- Category
- C++
- Title
- how to import getline in c++
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- how to put a class in a .h file c++
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- how to sort an array c++
- Category
- C++
- Title
- c++ map insert
- Category
- C++
- Title
- c++ file to string
- Category
- C++
- Title
- size of a matrix c++
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- how to print for limited decimal values in c++
- Category
- C++
- Title
- c++ find object in vector by attribute
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- how to sort a vector in reverse c++
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- vector stl c++
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- variable sized arrays hackerrank solution in c++
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- how to get input from the console in c++
- Category
- C++
- Title
- Html tab
- Category
- C++
- Title
- Runtime Error: Runtime ErrorBad memory access (SIGBUS)
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- FInd the element which appears more than n/2 times C++
- Category
- C++
- Title
- reverse in vector c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- how to read a comma delimited file into an array c++
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- visual studio 2019 c++ tutorial project
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- sfml basic program
- Category
- C++
- Title
- glfw initialize in c++
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- binary serach in c++
- Category
- C++
- Title
- gfg right view of tree
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- length of string in c++
- Category
- C++