@ -65,6 +65,19 @@ function gcd(a, b) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
C++ Code to Perform GCD-
|
||||||
|
```csharp
|
||||||
|
int gcd(int a,int b) {
|
||||||
|
int R;
|
||||||
|
while ((a % b) > 0) {
|
||||||
|
R = a % b;
|
||||||
|
a = b;
|
||||||
|
b = R;
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Python Code to Perform GCD using Recursion
|
Python Code to Perform GCD using Recursion
|
||||||
```Python
|
```Python
|
||||||
def gcd(a, b):
|
def gcd(a, b):
|
||||||
@ -87,7 +100,6 @@ static int gcd(int a, int b)
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
You can also use the Euclidean Algorithm to find GCD of more than two numbers.
|
You can also use the Euclidean Algorithm to find GCD of more than two numbers.
|
||||||
Since, GCD is associative, the following operation is valid- `GCD(a,b,c) == GCD(GCD(a,b), c)`
|
Since, GCD is associative, the following operation is valid- `GCD(a,b,c) == GCD(GCD(a,b), c)`
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user