# C program to find gcd of two numbers devquora

Posted On: Dec 23, 2020 ### What is a Number?

Number is an object that uses digits to perform mathematical task. Calculus that is a branch of mathematics included many numbers such as integer, whole number, real number, and imaginary numbers so on. Here, I will discuss about number to perform arithmetic addition operation. Moreover, Number is a combination of digits, some symbols and decimal point. For instance, 12 and 30 are numbers.

### What do you mean by factors?

Factors are numbers or quantity that when multiplied with one another produces a given number or expression.

For instance, 2, 2, 3 are the factors of 12 and 2, 3, 5 are the factors of 30.

### What do you mean by multiple?

A multiple of a number is the product of that number and an integer. For example, 10 is a multiple of 5 because 5 &times; 2 = 10, so 10 is divisible by 5 and 2.

Multiple of 4 are:

4, 8, 12, 16, 20, 24, 28, 32, 36, 40.....

Multiple of 6 are:

6, 12, 18, 24, 30, 36, 42, 48......

### What is GCD?

GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest number that divides both of them (without a remainder). For example, the GCD of two numbers, i.e., integer 8 and 12 is 4 because, both 8 and 12 are divisible by 1, 2, and 4 (the remainder is 0) and the largest positive integer among the factors 1, 2, and 4 is 4.

Other example,

The GCD of 20 and 28 is 4.

The GCD of 98 and 56 is 14.

The Greatest Common Divisor (GCD) is also known as the Highest Common Factor (HCF), or Greatest Common Factor (GCF), or Highest Common Divisor (HCD), or Greatest Common Measure (GCM).

### How to find GCD of two numbers?

• Step 1: Write the multipliers of both two numbers.
• Step 2: Take out the common between them.
• Step 3: Then to again multiply these common multipliers, Then we found the GCD of given two numbers.

### Demonstration for GCD of two numbers ### C program to find GCD of two numbers

```#include

// Recursive function to return gcd of a and b
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);
}

// Driver program to test above function
int main()
{
int a = 98, b = 56;
printf("%d",gcd(a, b));
return 0;
}
```

The output of the Program: Conclusion:

This Program stores two integers one by one into the int datatype. After that find the Greatest common factor of these two numbers as shown as output.

Never Miss an Articles from us.

## Related Articles

#### C Program to convert Decimal to Binary Number

A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

#### C program to reverse a string

This program reversed the entered string that means opposite of the previous string sequence...

#### C program to reverse an Integer number

Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..