C Armstrong NumberC Average of N NumbersC Biggest of Three NumbersC Common DivisorsC Composite NumberC Condense a NumberC Even NumberC Factorial of a NumberC Fibonacci SeriesC GCDC LCMC Leap YearC Multiplication TableC Number CombinationC Odd NumberC Palindrome NumberC Perfect NumberC Prime FactorC Prime NumberC Sum of DigitsC Swapping Two Numbers

C Array ProgramsC Converter ProgramsC Star Patterns ProgramC Number Patterns ProgramC Alphabet Patterns ProgramA largest number that exactly divides two or more integers.

In general, **Greatest Common Divisor** (GCD) is otherwise called as **Greatest Common Factor** (GCF) or **Highest Common Factor** (HCF)

**Tips**: It is recommended to use our online GCD calculator for better understanding.

The following table provides few examples of GCD of the given numbers.

Numbers | GCD |
---|---|

4, 10 | 2 |

6, 5 | 1 |

15, 30 , 45 | 15 |

In the following example, we will find the GCD of the given two numbers (45, 90).

C Compiler

#include <stdio.h>
int main() {
int num1 = 45;
int num2 = 90;
int gcd = 1;
int i;
for(i=2; i<=num1 && i<=num2; i++)
{
// Checks if i is factor of both integers
if((num1 % i == 0) && (num2 % i == 0))
gcd = i;
}
printf("GCD of %d and %d: %d", num1, num2, gcd);
return 0;
}

In the following example, we will find the GCD of any two given numbers.

C Compiler

#include <stdio.h>
int main() {
int num1, num2, i;
int gcd = 1;
printf("Enter (int) num1 = ");
scanf("%d", &num1);
printf("Enter (int) num2 = ");
scanf("%d", &num2);
for(i=2; i<=num1 && i<=num2; i++)
{
// Checks if i is factor of both integers
if((num1 % i == 0) && (num2 % i == 0))
gcd = i;
}
printf("\nGCD of %d and %d: %d", num1, num2, gcd);
return 0;
}

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.