GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and multiply common factors.

`// C program to demonstrate Basic Euclidean Algorithm ` `#include <stdio.h> ` ` ` `// Function to return gcd of a and b ` `int` `gcd(` `int` `a, ` `int` `b) ` `{ ` ` ` `if` `(a == 0) ` ` ` `return` `b; ` ` ` `return` `gcd(b % a, a); ` `} ` ` ` `// Driver program to test above function ` `int` `main() ` `{ ` ` ` `int` `a = 10, b = 15; ` ` ` `printf` `(` `"GCD(%d, %d) = %d\n"` `, a, b, gcd(a, b)); ` ` ` `a = 35, b = 10; ` ` ` `printf` `(` `"GCD(%d, %d) = %d\n"` `, a, b, gcd(a, b)); ` ` ` `a = 31, b = 2; ` ` ` `printf` `(` `"GCD(%d, %d) = %d\n"` `, a, b, gcd(a, b)); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

GCD(10, 15) = 5 GCD(35, 10) = 5 GCD(31, 2) = 1

**Time Complexity:** O(Log min(a, b))

Please refer complete article on Basic and Extended Euclidean algorithms for more details!

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Java Program for Basic Euclidean algorithms
- Euclidean algorithms (Basic and Extended)
- C Program for Extended Euclidean algorithms
- Pairs with same Manhattan and Euclidean distance
- Find HCF of two numbers without using recursion or Euclidean algorithm
- Minimum Sum of Euclidean Distances to all given Points
- Calculate the Square of Euclidean Distance Traveled based on given conditions
- Basic Operators in Java
- C Program for Program to find area of a circle
- C Program for Program for array rotation
- Lex Program to remove comments from C program
- Number Theory (Interesting Facts and Algorithms)
- Custom Building Cryptography Algorithms (Hybrid Cryptography)
- Write a program to calculate pow(x,n)
- Write a program to reverse digits of a number
- Program to find whether a no is power of two
- Program to find parity
- Write an Efficient C Program to Reverse Bits of a Number
- Write a program to print all permutations of a given string
- Write a program to add two numbers in base 14