Added C code of GCD (#26779)
* Added C code of GCD * fix: correct code format syntax
This commit is contained in:
committed by
Randell Dawson
parent
5181843c25
commit
87bbbeee8d
@ -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) {
|
||||
|
Reference in New Issue
Block a user