gcd function in c++
C++
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);
}int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
Also in C++:
- Title
- c++ cast char to string
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- passing array to function in c++
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- array<string, 7> c++
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++
- Title
- c++ public inheritance not getting protected
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- bool function in c++
- Category
- C++
- Title
- c++ cout int
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- primitive and non primitive data types in c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- insert elements in array in c++11
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- c++ class inheritance
- Category
- C++
- Title
- namespace file linking c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- how to switch to another branch in git
- Category
- C++
- Title
- check if intent has extras
- Category
- C++
- Title
- convert decimal to binary in c++
- Category
- C++
- Title
- #include
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- varint index
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- c++ how to add something at the start of a vector
- Category
- C++
- Title
- remove value from vector c++
- Category
- C++
- Title
- statement that causes a function to end in c++
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- c++ client service ros
- Category
- C++
- Title
- Combination Sum
- Category
- C++
- Title
- what is sigsegv error in c++
- Category
- C++
- Title
- how to get a letter from the user c++ string
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- c++ excel cell blank cells
- Category
- C++
- Title
- cs1955 unity vector3
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- c++ comment
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- c++ remove element from vector
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- what are the different ways to traverse a binary tree
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- c++ passing two dimensional array to function
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- elseif c++
- Category
- C++
- Title
- how to convert int to string c++
- Category
- C++
- Title
- Operator overloading in C++ Programming
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- how to find length of string in c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- how to calculate inverse trigonometric values in c++
- Category
- C++
- Title
- Find the minimum difference between pairs in a simple path of tree C++
- Category
- C++
- Title
- sorting of array in c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- call by reference c++ example
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- c++ clamp
- Category
- C++
- Title
- expected unqualified-id before 'if'
- Category
- C++
- Title
- subarray sum in c++
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- what is iterator in c++?
- Category
- C++