Added C code of GCD (#26779)

* Added C code of GCD

* fix: correct code format syntax
This commit is contained in:
codefreak_123
2019-02-14 05:10:56 +05:30
committed by Randell Dawson
parent 5181843c25
commit 87bbbeee8d

View File

@ -65,6 +65,27 @@ function gcd(a, b) {
}
```
C code to perform GCD using recursion
```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);
}
```
C++ Code to Perform GCD-
```csharp
int gcd(int a,int b) {