- C program to test if a number is a power of 2
- C program to multiply two number without using multiplication(*) operator
- C program to display Fibonacci series
- C program to compare two numbers without using relational operators
- C program to convert roman number into decimal number
- C program to encrypt and decrypt the string
- C program to make calculator using switch case
- C program to convert temperature from degree celsius to fahrenheit
- Selection sort in C programming
- Binary search in C programming
- C program to sort array using bubble sort algorithm
- Linear Search in C Programming – Program and Explanation
- C program to swap two numbers
- C program to find LCM of two numbers
- C program to find GCD of two numbers
- C program to find LCM and GCD using recursion
- C program to display prime numbers between two numbers using function and without using function
- C program to check whether a string is palindrome or not
- C program to read a character from keyboard and print it in reverse case i.e if input is lower case output will be upper case and vice versa
- C program to check whether a number is prime or not
- C program to check whether a number is positive, negative or zero
- C program to check whether a number is palindrome or not
- C program to check leap year
- C program to check Armstrong number
- C program to calculate the area of square with and without using function
- C program to calculate mean using arrays
- C program to calculate area of circle

This is a **C program to find GCD of two numbers**.

The Greatest Common Divisor (GCD) or Highest Common Factor (HCF) of a given integer is the highest positive integer that divides the given integer without remainder.

For better understanding, the concept of following c programming topics is required

```
#include <stdio.h>
int main()
{
int x, y, i, gcd;
printf("Enter two integer values: \n");
scanf("%d %d", &x, &y);
for (i = 1; i <= x && i <= y; i++)\
{
if (x % i == 0 && y % i == 0)
gcd = i;
}
printf("GCD of %d and %d is: %d", x, y, gcd);
return 0;
}
```

**Output**

[adsense1]

**Explanation**

The program logic to calculate GCD or HCF is simple. `fo`

r loop continue till the value of `i`

is equal to `x`

or `y`

and `if`

condition checks whether the remainder of `x`

and `y`

when divided by `i`

is equal to 0 or not.

```
#include <stdio.h>
int main()
{
int x, y, temp, gcd;
printf("Enter two integer: \n");
scanf("%d %d", &x, &y);
while (y != 0)
{
temp = y;
y = x % y;
x = temp;
}
gcd = x;
printf("GCD of given integers is: %d", gcd);
return 0;
}
```

**Output**