C program to calculate GCD of Two Numbers

In this tutorial you will learn about the C program to calculate GCD of Two Numbers and its application with practical example.

C program to calculate GCD of Two Numbers

In this tutorial, we will learn to create a C program that will calculate the GCD of Two Numbers in C programming.

Prerequisites

Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C Programming.
  • Arithmetic Operators in C Programming.
  • While Loop in the C programming.

What is the GCD of Two Numbers?

In the GCD of two numbers, it means the greatest common divisor of two numbers is the largest number that divides both of them. It can also be called the highest common factor.

Algorithm:-

Program Description.

In today’s program, we will first take the input numbers from the user in integer format. And after that, we will pass that variable to a for loop and the conditional statements to check the greatest common divisor of two numbers. At last, we will print the result of the greatest common divisor of those numbers to the user.

With the help of the below program, we can calculate the GCD of Two Numbers.

Program Code:-

Output:-

In the above program, we have first initialized the required variable.

  • n1 = it will store the input integer value.
  • n2 = it will store the input integer value.
  • i = it will store the integer value for the loop control.
  • gcd = it will hold the value for the output gcd.

Taking the input numbers from the user.

Calculating the GCD of two numbers.

Printing the output of the program.

In this tutorial we have learn about the C program to calculate GCD of Two Numbers and its application with practical example. I hope you will like this tutorial.